Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How To Create WooCommerce Custom Order Status

April 11, 2017

3 Min Read
custom WooCommerce order status
Reading Time: 3 minutes

In this article, I will demonstrate how you could add custom WooCommerce order status actions. The intent here is to show how you could modify order data, add information to orders, export order data externally, or run any general action that requires order details.

Best WooCommerce Web Hosting

Another important thing in this context is that these statuses trigger further actions. You need to provide WooCommerce code for these actions. In many instances, this code is custom written as a response for particular statuses.

Custom WooCommerce Order Status

  • Payment Pending
  • Processing
  • On Hold
  • Completed
  • Cancelled
  • Refunded
  • Failed

WooCommerce Order status

WooCommerce has changed the order structure to support partial and automatic refunds from the WooCommerce admin. Order statuses are now saved as a custom post status, just like the draft, scheduled, or published for posts.

Adding a custom post status now requires a bit more code than it did before. However, the process is more streamlined now from the developer’s perspective.

Addition of Custom WooCommerce Order Status

Some shops require customized order statuses such as Awaiting shipment, Building. These statuses are essential for their unique business requirements. Fortunately, adding these statutes is easy and require just a tiny bit of custom code.

function register_shipment_arrival_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', 'register_shipment_arrival_order_status' );

function add_awaiting_shipment_to_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', 'add_awaiting_shipment_to_order_statuses' );

Custom Order Status Shipment Arrival

I added the post status using the WordPress register_post_status() function. Notice that the first thing in this function is the slug for the order status, prefixed by “wc-” for WooCommerce.

I then created an array, that contains the data that defines the custom post status. The label is what will be displayed, so I can change it to the exact name of the order status.

function add_awaiting_shipment_to_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;

The add_awaiting_shipment_to_order_statuses() function is going to add this new custom post status into the list of available order statuses within the WooCommerce Orders and Edit Orders pages. These statuses are then available for use on these pages.

The foreach loop here goes through the list of current order statuses until it finds the one I want. In this case, I am going to insert Shipment Arrival after Processing order status. That is what the if() part is doing here – I say, “If the order status is ‘processing’, add in Shipment Arrival here, then continue going through order statuses.”

woocommerce order status plugin

Conclusion

In this tutorial, I discussed how to change the order structure of WooCommerce so that I could use custom order status on my WooCommerce store. If you need help with the idea or would like to add to the discussion, do leave a comment below.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Your WooCommerce Store Needs A Reliable Host

With no compromise on Performance, Security & Support.

Owais Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at owais.alam@cloudways.com

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!