Add custom order status in WooCommerce

There are many options available for order status but what if our business needs more customized options like Shipment Arrival, Awaiting shipment, or many more. These statuses are necessary to be added according to different business requirements. So The main agenda for this snippet is to see how we can add more information to orders. In the below image you can see the default status provided by Woocommerce

Before applying snippet

Now let’s look at the tiny little code to add custom status. Add this to your function.php in your child theme.

// custom order status
// registering the custom order status by passing details in an array
 
function wps_register_custom_order_status() {

    register_post_status( 'wc-arrival-shipment', array(
        'label'                     => 'Shipment Arrival',
        'public'                    => true,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'exclude_from_search'       => false,
        'label_count'               => _n_noop( 'Shipment Arrival <span class="count">(%s)</span>', 'Shipment Arrival <span class="count">(%s)</span>' )
    ) );

}

add_action( 'init', 'wps_register_custom_order_status' );

// adding custom order status

function wps_add_custom_order_statuses( $order_statuses ) {

    $new_order_statuses = array();

    foreach ( $order_statuses as $key => $status ) {
        $new_order_statuses[ $key ] = $status;
        if ( 'wc-processing' === $key ) {
            $new_order_statuses['wc-arrival-shipment'] = 'Shipment Arrival';
        }
    }

    return $new_order_statuses;
}

add_filter( 'wc_order_statuses', 'wps_add_custom_order_statuses' );

In the above function first, we are registering the order status by passing details of the order in an array.
Secondly, we are adding the status to the order list by running foreach loop.

After applying snippet

Edit WooCommerce Products from Frontend

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top