Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add woocommerce custom order status?

I have added new custom order status to woocommerce by using 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 edit order and changed the order status to newly added custom order status and click on Save Order button. After loading the order status automatically changes to Pending Order not stands in newly added custom order...

enter image description here

enter image description here

How to overcome this problem...?

like image 876
NNKK Avatar asked Apr 22 '15 06:04

NNKK


People also ask

How does WooCommerce order status work?

Order Statuses An order also has a Status. Order statuses let you know how far along the order is, starting with “Pending payment” and ending with “Completed.” The following order statuses are used: Pending payment — Order received, no payment initiated. Awaiting payment (unpaid).

How do I get WooCommerce order notification?

Check your Email SettingsDouble-check that “Enable this email notification” is ticked for order notifications at WooCommerce > Settings > Emails and select the Processing Order email template. An additional test should be setting the Email Type to plain text.


1 Answers

The order status that you're registering wc-custom-order-status is too long - 22 characters. This results in saving only the first 20 characters of the post status, which makes it invalid and causes your issue.

The order statuses are registered as post statuses, and post statuses have a limitation of 20 characters.

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

I'm also posting the updated version of your code, just for reference (I've only 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' );
like image 106
Marin Atanasov Avatar answered Sep 28 '22 07:09

Marin Atanasov