WooCommerce custom order state

WooCommerce custom order state

WooCommerce custom order state

Before diving into the code, consider this:

No code is better than no code.

So what is a good use-case for custom WooCommerce order state? More often than not, the product you sell will involve some kind of operations that you want to track transparently from customer, for example ordering the materials from a supplier, or send it off to a custom shop. WooCommerce is so matured it is possible to implement complex order processing pipeline just utilizing its note system. I mean obviously you can add a note every time you need to order from a supplier. The down side of this is the staff might forgot the details, or the note can get inconsistent over time. Moreover since the note is just text it is hard to keep track and filter the order of various state. Custom order state can really stream line the whole operation.

Adding custom order state to WooCommerce

Let’s say you’re selling leather goods, and allow customers to have their name engrave into the tag. You have a partner that do this for you and want to track the items you sent them. Here’s the code:

Some note about the names:

  • The status have wc prefix just for simplicity. There are some internal WooCommerce thing involve this.
  • They are Wordpress post_status, so they must not be longer than 20 characters. This cost me 4 hour digging :(

Add custom order process actions

For better user experience, we can also add a couple of custom order actions. In my case these action also helps send the order information to our API.

Bonus: Display order status column in the order list

With some more code we can display the order status nicely in the admin interface:

Conclusion

Overall, the process is not challenging at all, but the information is so scattered I decided to put together a tutorial. Hope you find it helpful.