How To Create WooCommerce Custom Order Status

by Owais Alam  April 11, 2017

In this article, I will demonstrate how you could add WooCommerce custom order 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.

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.

WooCommerce Custom Order Status

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

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 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 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.

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.

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.”

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.

Start Creating Web Apps on Managed Cloud Servers Now!

Easy Web App Deployment for Agencies, Developers and E-Commerce Industry

About 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

Stay Connected:

You Might Also Like...