How to add custom woocommerce order status?

I added a new custom order status in woocommerce using the following function.

// Register New Order Statuses function wpex_wc_register_post_statuses() { register_post_status( 'wc-custom-order-status', 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', '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( 'Shipping In Progress', 'WooCommerce Order status', 'text_domain' ); return $order_statuses; } add_filter( 'wc_order_statuses', 'wpex_wc_add_order_statuses' ); 

whenever I go to reorder and change the order status to the newly added order status and click the "Save Order" button. After loading, the order status automatically changes to a Pending order, and not to a new added custom order ...

enter image description here

enter image description here

How to overcome this problem ...?

+8
function wordpress woocommerce
source share
1 answer

The order status you register with wc-custom-order-status is too long - 22 . This only saves the first 20 characters of the message status, which makes it invalid and causes a problem.

Order statuses are recorded as message statuses, and message statuses are limited to 20 characters.

I suggest that you update your wc-custom-order-status name to wc-shipping-progress , which exactly matches 20 characters.

I am also posting an updated version of your code, for reference only (I just changed the status name):

 // Register New Order Statuses function wpex_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', 'wpex_wc_register_post_statuses' ); // Add New Order Statuses to WooCommerce function wpex_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', 'wpex_wc_add_order_statuses' ); 
+10
source share

All Articles