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

How to Sort WooCommerce Custom Order Status Sequence?

While having multiple custom statuses, you may want to prioritize some statuses to be placed at the top or specifically before a specific status. Placing the order status where you want in the Order Edit Dropdown matters based on your preference and convenience to identify specific order status quickly.

Solution: Rearrange WooCommerce Custom Order Status Sequence

In the code snippet below, a custom status such as ‘Awaiting shipping’ is created and it is placed right before the status ‘completed’ in the admin edit orders page.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
add_action( 'init', 'ts_register_awaiting_shipping_status' );
function ts_register_awaiting_shipping_status() {
register_post_status(
'wc-ts-shipping',
array(
'label' => 'Awaiting shipping',
'public' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Awaiting shipping (%s)', 'Awaiting shipping (%s)' )
)
);
}
// Add registered status to list of WC Order statuses
add_filter( 'wc_order_statuses', 'ts_add_status_to_list' );
function ts_add_status_to_list( $order_statuses ) {
$new = array();
foreach ( $order_statuses as $id => $label ) {
if ( 'wc-completed' === $id ) { // before "Completed" status
$new['wc-ts-shipping'] = 'Awaiting shipping';
}
$new[$id] = $label;
}
return $new;
}
add_action( 'init', 'ts_register_awaiting_shipping_status' ); function ts_register_awaiting_shipping_status() { register_post_status( 'wc-ts-shipping', array( 'label' => 'Awaiting shipping', 'public' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( 'Awaiting shipping (%s)', 'Awaiting shipping (%s)' ) ) ); } // Add registered status to list of WC Order statuses add_filter( 'wc_order_statuses', 'ts_add_status_to_list' ); function ts_add_status_to_list( $order_statuses ) { $new = array(); foreach ( $order_statuses as $id => $label ) { if ( 'wc-completed' === $id ) { // before "Completed" status $new['wc-ts-shipping'] = 'Awaiting shipping'; } $new[$id] = $label; } return $new; }
add_action( 'init', 'ts_register_awaiting_shipping_status' );

function ts_register_awaiting_shipping_status() {
    register_post_status(
        'wc-ts-shipping',
        array(
            'label'                  => 'Awaiting shipping',
            'public'                 => true,
            'show_in_admin_status_list' => true,
            'label_count'            => _n_noop( 'Awaiting shipping (%s)', 'Awaiting shipping (%s)' )
        )
    );
}
// Add registered status to list of WC Order statuses
add_filter( 'wc_order_statuses', 'ts_add_status_to_list' );

function ts_add_status_to_list( $order_statuses ) {
    $new = array();

    foreach ( $order_statuses as $id => $label ) {
        if ( 'wc-completed' === $id ) { // before "Completed" status
            $new['wc-ts-shipping'] = 'Awaiting shipping';
        }
        $new[$id] = $label;
    }

    return $new;
}

Output

The code loops through the existing order statuses and when it encounters the ‘completed’ status, it adds the new status ‘Awaiting shipping’ to the list just before “Completed” status.

How to Sort WooCommerce Custom Order Status Sequence? - Tyche Softwares

Additionally, you can aslo integrate the functionality to add custom bulk actions to WooCommerce Admin order list.


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.