Posted on

WooCommerce: Set Custom Order Status for New Orders

All WooCommerce orders go to either “processing”, “completed”, “on-hold” and other default order statuses based on the payment method and product type.

Sometimes these statuses are not enough. For example, you might need to mark certain orders in a different way for tracking, filtering, exporting purposes. Or you might want to disable default emails by bypassing the default order status changes.

Either way, setting a custom order status automatically once the order is processed is quite easy. And today we’ll see which PHP snippets you need in order to make this work!

WooCommerce: set a custom order status during checkout

PHP Snippet: Assign Custom Order Status during WooCommerce Checkout Process


/** 
* @snippet       Set Custom Order Status during Checkout
* @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055 
* @sourcecode    https://businessbloomer.com/?p=77911
* @author        Rodolfo Melogli 
* @compatible    WooCommerce 3.4.4 
*/ 

// ---------------------
// 1. Register Order Status

add_filter( 'woocommerce_register_shop_order_post_statuses', 'bbloomer_register_custom_order_status' );

function bbloomer_register_custom_order_status( $order_statuses ){
	
	// Status must start with "wc-"
	$order_statuses['wc-custom-status'] = array(											
	'label'                     => _x( 'Custom Status', 'Order status', 'woocommerce' ),
	'public'                    => false,											
	'exclude_from_search'       => false,											
	'show_in_admin_all_list'    => true,											
	'show_in_admin_status_list' => true,											
	'label_count'               => _n_noop( 'Custom Status <span class="count">(%s)</span>', 'Custom Status <span class="count">(%s)</span>', 'woocommerce' ),										
	);		
	return $order_statuses;
}

// ---------------------
// 2. Show Order Status in the Dropdown @ Single Order and "Bulk Actions" @ Orders

add_filter( 'wc_order_statuses', 'bbloomer_show_custom_order_status' );

function bbloomer_show_custom_order_status( $order_statuses ) {	   
	$order_statuses['wc-custom-status'] = _x( 'Custom Status', 'Order status', 'woocommerce' );       
	return $order_statuses;
}

add_filter( 'bulk_actions-edit-shop_order', 'bbloomer_get_custom_order_status_bulk' );

function bbloomer_get_custom_order_status_bulk( $bulk_actions ) {
	// Note: "mark_" must be there instead of "wc"
	$bulk_actions['mark_custom-status'] = 'Change status to custom status';
	return $bulk_actions;
}



// ---------------------
// 3. Set Custom Order Status @ WooCommerce Checkout Process

add_action( 'woocommerce_thankyou', 'bbloomer_thankyou_change_order_status' );

function bbloomer_thankyou_change_order_status( $order_id ){
	if( ! $order_id ) return;
	$order = wc_get_order( $order_id );

	// Status without the "wc-" prefix
	$order->update_status( 'custom-status' );
}

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

14 thoughts on “WooCommerce: Set Custom Order Status for New Orders

  1. The code removes “Processing” and “Complete” from the quick-view when clicking the “eye”. Any fix for that?

    1. Hey Bjornen, thanks for your comment. Screenshot please?

  2. Hi,
    Can we have more than one custom status from same function ? pl advice.

    Thanks

    1. Hey Kumar – yes you can ๐Ÿ™‚ But I can’t share this here – thanks for the understanding.

  3. This article was super helpful! We use woocommerce for our sales and checkouts for out website. With so many backend details it’s hard to know what changes what, unless your an expert!

    1. Cool ๐Ÿ™‚

  4. It worked on single order page drop down. Thanks.

    Is there is way it also can work on order page (dropdown Bulk Actions)

    1. Hey Mark – thanks so much for your comment! Part #2 does that already ๐Ÿ™‚

    2. Hi ,
      It’s visible only inside single order page. It doesn’t display (drop down) on order page .
      Pl check and advice.

    3. Fixed ๐Ÿ™‚

  5. It Worked . But all new orders are getting custom status . How do we keep it on manual basis? I want to keep as processing Status for all new orders.

    Also – Moment I removed Snippet from function file . All orders with custom status disappeared from order management page .
    Pl check

    1. Hey Kumar ๐Ÿ™‚

      1) Just delete snippet part #3
      2) Reactivate the snippet – change the order status to e.g. Processing – disable the snippet

      Hope this helps ๐Ÿ™‚

  6. Was Waiting for This .. Can i change keyword from custom to SHIPPED ?
    Pl advice. Thanks.

    1. Of course Kumar! Just change all “custom status” occurrences to “shipped” ๐Ÿ™‚

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.