Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
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.

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