Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Add/Set Custom Order Status in WooCommerce Stores

Orders at a Woocommerce go through several stages from the initial placement to final fulfillment. In order to simplify order tracking, WooCommerce offers several order statuses to make sense of the flow of orders. At the moment, WooCommerce offers the following seven statuses:

  • Completed
  • Processing
  • Pending payment
  • On hold
  • Refunded
  • Cancelled
  • Failed

All these statuses trigger actions that define the store’s business logic for a particular status. You could provide Custom code for each status to carry out actions that conform to the store’s policies.

The good thing is that you could define custom order statuses as well and then add custom code so that the store could take the action in response to the selection of the custom status. To demonstrate the process, I will add a custom order status “Shipping In Progress”.

The following code snippets take care of the process. Remember that these snippet will go into functions.php file located in the theme folder.:

Register New Order Status

function wpblog_wc_register_post_statuses() {
register_post_status( 'wc-shipping-progress', array(
'label' => _x( 'Shipping In Progress', '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', 'wpblog_wc_register_post_statuses' );

Add New Order Statuses to WooCommerce

function wpblog_wc_add_order_statuses( $order_statuses ) {
$order_statuses['wc-shipping-progress'] = _x( 'Shipping In Progress', 'WooCommerce Order status', 'text_domain' );
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'wpblog_wc_add_order_statuses' );

Here’s how the custom order status would look in action:

Code Explanation

The order status that you’re registering through wc-shipping-progress is too long (-22). This will save the first 20 characters of the post status, which makes it invalid and causes errors.

The order statuses are registered as post statuses with a limit of 20 characters. wc-shipping-progress ensures that the limit remains at exactly 20 characters in length.

The wpblog_wc_add_order_statuses() function adds the new custom post status (also known as order status) into the list of available order statuses within the WooCommerce Orders and Edit Orders pages.

The post How to Add/Set Custom Order Status in WooCommerce Stores appeared first on WPblog.



This post first appeared on WordPress Tutorials And Guides, please read the originial post: here

Share the post

How to Add/Set Custom Order Status in WooCommerce Stores

×

Subscribe to Wordpress Tutorials And Guides

Get updates delivered right to your inbox!

Thank you for your subscription

×