Create custom order status in WooCommerce

Categories: CMS, Wordpress

Use this code to create a custom order status in WooCommerce:

// Order Status Partial Shippment

// Register new status
function register_partial_shippment_order_status() {
    register_post_status( 'wc-partial-shippment', array(
        'label'                     => 'Partial Shippment',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Partial Shippment (%s)', 'Partial Shippment (%s)' )
    ) );
}
add_action( 'init', 'register_partial_shippment_order_status' );

// Add to list of WC Order statuses
function add_partial_shippment_to_order_statuses( $order_statuses ) {
 
    $new_order_statuses = array();
 
    // add new order status after processing
    foreach ( $order_statuses as $key => $status ) {
 
        $new_order_statuses[ $key ] = $status;
 
        if ( 'wc-processing' === $key ) {
            $new_order_statuses['wc-partial-shippment'] = 'Partial Shippment';
        }
    }
 
    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_partial_shippment_to_order_statuses' );
«
»