Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
00 Days
00 Hours
00 Minutes
00 Seconds

How to Programmatically Delete Custom Order Statuses in WooCommerce?

Whether you have set up a custom order status plugin or used code snippets to create a custom order status, it is common to deactivate the plugin or delete custom order statuses. Based on your products/services if you have created multiple custom order statuses and when you want to delete them, doing it manually is a tedious task. With custom coding you can delete these unused custom order statuses.

Solution: Delete Custom Order Statuses

The code snippet below will delete certain unused or obsolete statuses that is no longer needed.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
add_filter( 'wc_order_statuses', 'ts_add_outofstock_order_statuses' );
function ts_remove_order_status( $statuses ) {
if( isset( $statuses['wc-outofstock'] ) ){
unset( $statuses['wc-outofstock'] );
}
return $statuses;
}
add_filter( 'wc_order_statuses', 'ts_remove_order_status', 10);
add_filter( 'wc_order_statuses', 'ts_add_outofstock_order_statuses' ); function ts_remove_order_status( $statuses ) { if( isset( $statuses['wc-outofstock'] ) ){ unset( $statuses['wc-outofstock'] ); } return $statuses; } add_filter( 'wc_order_statuses', 'ts_remove_order_status', 10);
add_filter( 'wc_order_statuses', 'ts_add_outofstock_order_statuses' );
function ts_remove_order_status( $statuses ) {
    if( isset( $statuses['wc-outofstock'] ) ){
        unset( $statuses['wc-outofstock'] );
    }
    return $statuses;
}

add_filter( 'wc_order_statuses', 'ts_remove_order_status', 10);

Output

Let’s say for example, if you have created a custom order status called “Out of Stock” to track orders that are temporarily not available. But when the products are restocked or when you don’t want this status in the order stages of the fulfillment process, you can use the above code snippet and delete it. I have created a custom order status such as ‘Out Of Stock’ as shown in the image given below.

Delete Custom Order Statuses

The code will delete the status ‘Out of Stock’ from the list of available order statuses.

Delete Custom Order Statuses

Alternatively, once the payment is done for all orders in one go, you can automatically complete order in WooCommerce when they go to the processing status.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of


0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.