Menu Close

Create WooCommerce Custom Order Statuses For WordPress


WooCommerce is an awesome WordPress plugin to sell products online. And today I’d like to show you how to create plugin to allow you to create custom order statuses. By default WooCommerce provides these order statuses:

  • cancelled
  • completed
  • failed
  • on-hold
  • pending
  • processing
  • refunded

But what if you want to add new statuses, or maybe modify existing ones? Below is an example showing you how easy it is to add a new order status to your WooCommerce orders.

Visually here is the final result:


Register New WooCommerce Order Status

Previously WooCommerce used a “shop_order_status” taxonomy so adding new order statuses was a bit tricky, however, now it’s easier then ever! Have a look at the code below for an example.

// Register New Order Statuses
function wpex_wc_register_post_statuses() {
	register_post_status( 'wc-custom-order-status', array(
		'label'						=> _x( 'Custom Order Status Name', 'WooCommerce Order status', 'text_domain' ),
		'public'					=> true,
		'exclude_from_search'		=> false,
		'show_in_admin_all_list'	=> true,
		'show_in_admin_status_list'	=> true,
		'label_count'				=> _n_noop( 'Approved (%s)', 'Approved (%s)', 'text_domain' )
	) );
add_filter( 'init', 'wpex_wc_register_post_statuses' );

// Add New Order Statuses to WooCommerce
function wpex_wc_add_order_statuses( $order_statuses ) {
	$order_statuses['wc-custom-order-status'] = _x( 'Custom Order Status Name', 'WooCommerce Order status', 'text_domain' );
	return $order_statuses;
add_filter( 'wc_order_statuses', 'wpex_wc_add_order_statuses' );

If you want to add multiple new order statuses simply duplicate the register_post_status function inside the wpex_wc_register_post_statuses function as many times as you want making sure to alter the ID and the labels accordingly. Then add the new order status to the $order_statuses array in the wpex_wc_add_order_statuses function.

View Source
Posted in WordPress