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

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.

Sort WooCommerce Custom Order Status Sequence

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