WooCommerce – Custom Order Status

Last updated 2 years ago

PHP
add_action( 'init', function() {
 
    register_post_status( 'wc-backorder', [
        'label' => 'On backorder',
        'public' => true,
        'exclude_from_search' => false,
        'show_in_admin_all_list' => true,
        'show_in_admin_status_list' => true,
        'label_count' => _n_noop( 'On backorder (%s)', 'On backorder (%s)' )
    ] );
 
} );
 
add_filter( 'wc_order_statuses', function( $order_statuses ) {
 
    $new_order_statuses = [];
    foreach( $order_statuses as $key => $status ) {
        $new_order_statuses[ $key ] = $status;
        if( 'wc-processing' === $key ) {
            $new_order_statuses['wc-backorder'] = 'On backorder';
        }
    }
 
    return $new_order_statuses;
 
} );
 
add_filter( 'woocommerce_reports_order_statuses', function( $statuses ) {
 
    $statuses[] = 'wc-backorder';
 
    return $statuses;
 
} );

All code snippets are licensed GPLv2 or later unless otherwise stated.