MdMasud

WordPress, Laravel, Flutter

How to add a custom Order Status in WooCommerce and set it as the default

·

,

WooCommerce has default order statuses such as Pending Payment, Processing, and Completed.
However, Some online businesses need their own custom workflow. For example, you may want new orders to start in a “Price Request” status instead of “Pending”.

In this guide, I explain how to register new order statuses and set one of them as the default when an order is created.


Registering custom Order Statuses

WooCommerce uses register_post_status() to add new statuses.
Below we add four custom statuses to WordPress:

add_action('init', 'add_more_status_to_order');

function add_more_status_to_order()
{
    register_post_status('wc-price-request', [
        'label'                     => _x('Price request', 'Order status', 'my-domain'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop('Price request <span class="count">(%s)</span>', 'Price request <span class="count">(%s)</span>', 'my-domain'),
    ]);

    register_post_status('wc-quoted', [
        'label'                     => _x('Quoted', 'Order status', 'my-domain'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop('Quoted <span class="count">(%s)</span>', 'Quoted <span class="count">(%s)</span>', 'my-domain'),
    ]);

    register_post_status('wc-pending-pricing', [
        'label'                     => _x('Pending pricing', 'Order status', 'my-domain'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop('Pending pricing <span class="count">(%s)</span>', 'Pending pricing <span class="count">(%s)</span>', 'my-domain'),
    ]);
}


Setting a Custom Default Order Status

By default, WooCommerce sets all new orders to “Pending”.
If you want every new order to start as “Price Request”, use this hook:

add_action('woocommerce_new_order', 'set_default_order_status', 99, 1);

function set_default_order_status($order_id)
{
    $order = wc_get_order($order_id);
    if ($order && $order->get_status() === 'pending') {
        $order->update_status('price-request', 'Default status.');
    }
}


This helps when your business process is different from a standard retail store.


By registering custom statuses and setting one as the default, you can build an order workflow that matches the business requirements.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *