How to Hide Order Status In WooCommerce

WooCommerce Hide Order StatusDo you want to hide core order statuses in your WooCommerce store? Recently, a client wanted me to hide some of the order statuses in his WooCommerce store. In this post, you will see how you can easily remove some order statuses and how to create custom ones.

WooCommerce Hide Order Status

For various reasons, you might want to hide some of the core order statuses. However, the default version of WooCommerce allows you to mark orders with one of the following statuses completed, processing, pending payment, on hold, refunded, cancelled, or failed.

Many plugins allow you to manage order statuses, and one of them is the ‘WooCommerce Order Status Manager’ plugin that is priced at $49.WooCommerce Order Status Manager

This might be an expensive solution for your store, but there is an easy way to do this. In the current version of WooCommerce, order statuses are saved as a custom post status, just like the draft, scheduled, or published for posts.

How to Hide Order Status

With that said, let us look at how you can hide order status in WooCommerce using a code snippet. To check the default order status messages, log into your WordPress site and access the Dashboard as the admin user. Then, click on WooCommerce > Orders. You will see this:order status back end

These messages are also displayed in the front-end when a customer tries to place an order. This can be accessed by clicking on My Account > Orders, as shown below:order status front end

Steps to Hide Core Order Statuses

It is worth mentioning that when you hide core order statuses, make sure that there are no products with that status. Moreover, you should make sure that your WooCommerce shop does not use that status anywhere, because it can lead to errors. For example, if you do not plan to make refunds in your WooCommerce store, you can hide the Refund status.

The reason why we cannot remove all the core order statuses is that plugins use order statuses, even the ones you do not use in your workflow. Plugins like payment gateways, always assume that the core order statuses are present. If they are not there, they will break

Here are the steps that you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to add the function to hide core order statuses in your WooCommerce store.
  3. Add the following code to the functions.php file:
/*

 * Removing core order statuses

 * @param array $wc_statuses_arr Array of all order statuses on the website

 */

function njengah_remove_order_statuses( $wc_statuses_arr ){

            // Processing

            if( isset( $wc_statuses_arr['wc-processing'] ) ) { // if exists

                        unset( $wc_statuses_arr['wc-processing'] ); // remove it from array

            }

            // Refunded

            if( isset( $wc_statuses_arr['wc-refunded'] ) ){

                        unset( $wc_statuses_arr['wc-refunded'] );

            }

            // On Hold

            if( isset( $wc_statuses_arr['wc-on-hold'] ) ){

                        unset( $wc_statuses_arr['wc-on-hold'] );

            }

            // Failed

            if( isset( $wc_statuses_arr['wc-failed'] ) ){

                        unset( $wc_statuses_arr['wc-failed'] );

            }

            // Pending payment

            if( isset( $wc_statuses_arr['wc-pending'] ) ){

                        unset( $wc_statuses_arr['wc-pending'] );

            }

            // Completed

            //if( isset( $wc_statuses_arr['wc-completed'] ) ){

            //    unset( $wc_statuses_arr['wc-completed'] );

            //}

            // Cancelled

            //if( isset( $wc_statuses_arr['wc-cancelled'] ) ){

            //    unset( $wc_statuses_arr['wc-cancelled'] );

            //}

            return $wc_statuses_arr; // return result statuses

}

add_filter( 'wc_order_statuses', 'njengah_remove_order_statuses' );
  1. This is the outcome on the front end:hide order statuses
  2. To add a custom order status, add the following code in the functions.php file:
/**

* Register new status with ID "wc-njengah-shipment" and label "Awaiting shipment"

*/

function njengah_register_awaiting_shipment_status() {
register_post_status( 'wc-njengah-shipment', array(

'label'              => 'Awaiting shipment',

'public' => true,

'show_in_admin_status_list' => true, // show count All (12) , Completed (9) , Awaiting shipment (2) ...

'label_count'   => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' )

) );
}

add_action( 'init', 'njengah_register_awaiting_shipment_status' );

/*

* Add registered status to list of WC Order statuses

* @param array $wc_statuses_arr Array of all order statuses on the website

*/

function njengah_add_status( $wc_statuses_arr ) {
$new_statuses_arr = array();

// add new order status after processing

foreach ( $wc_statuses_arr as $id => $label ) {

$new_statuses_arr[ $id ] = $label;

if ( 'wc-completed' === $id ) { // after "Completed" status

$new_statuses_arr['wc-njengah-shipment'] = 'Awaiting shipment';

}

}
return $new_statuses_arr;

// if order status order doesn't matter for you you can remove lines 21-32 and uncomment the following 35-36

// $wc_statuses_arr['wc-njengah-shipment'] = 'Awaiting shipment';

// return $wc_statuses_arr;
}

add_filter( 'wc_order_statuses', 'njengah_add_status' );
  1. This is the outcome:add custom order status

Conclusion

In this post, you have seen how you can hide core order statuses. However, it is important to note that the order status you want to delete is not being used anywhere on your store, because it can lead to errors. Moreover, I have shared how to add custom order status. If you are not familiar in handling code, please contact a qualified WordPress developer.

Similar Articles


Customer Reviews

NJENGAH

Customer Reviews

Jeffrey Todd 04/07/2020

Exceptional Plugin & Service

I'm in the process of building my new website, and I had a question about changing some text within the WooCommerce plugin. I was spinning my wheels trying to figure it out. Joe reached back and worked with me - going above and beyond! - until I fully understood how to effectively change what I wanted. How can you ask for more than that? I highly recommend WooCommerce (and Joe!), the plugin and service are exceptional!
-Jeffrey Todd (MyLifeChart.com)