How to create a custom order status in woocommerce

I’ve tried the below code to create custom status.

add_action( 'init', function() {
    $term = get_term_by( 'name', 'shipped', 'shop_order_status' );
    if ( ! $term ) {
        wp_insert_term( 'shipped', 'shop_order_status' );
    }
} );

But it is not working. I tried some other methods also. Please can anyone help me on this..

Related posts

1 comment

  1. You need to first register your custom status and then add it to the order statuses array.

    function register_shipped_order_status() {
        register_post_status( 'wc-shipped', array(
            'label'                     => 'Shipped',
            'public'                    => true,
            'exclude_from_search'       => false,
            'show_in_admin_all_list'    => true,
            'show_in_admin_status_list' => true,
            'label_count'               => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped <span class="count">(%s)</span>' )
        ) );
    }
    add_action( 'init', 'register_shipped_order_status' );
    
    
    add_filter( 'wc_order_statuses', 'custom_order_status');
    function custom_order_status( $order_statuses ) {
        $order_statuses['wc-shipped'] = _x( 'Shipped', 'Order status', 'woocommerce' ); 
        return $order_statuses;
    }
    

Comments are closed.