Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Change WooCommerce Order Status for Orders Placed from Certain Regions?

Want to spotlight orders placed from specific regions in your dashboard within the WooCommerce Orders table? You might need this when you have to provide extra attention to the orders placed from certain regions. This handy snippet lets you do just that!

Solution: Change WooCommerce Order Status for Orders Placed from Certain Regions

The code snippet will help to change the status of orders placed from the regions defined in the array($allowed_states = array(‘KA’, ‘MH’, ‘TN’); to the ‘completed’ status.

add_action('woocommerce_order_status_changed', 'ts_change_status_by_state');

function ts_change_status_by_state($order_id)
{
    if (!$order_id) {
        return;
    }

    // Get the order object
    $order = wc_get_order($order_id);

    // Get the billing state of the customer
    $billing_state = $order->get_billing_state();

    // Array of billing states to check against
    $allowed_states = array('KA', 'MH', 'TN');

    // Check if the billing state is in the array of allowed states
    if (in_array($billing_state, $allowed_states)) {
        // If the billing state is in the array of allowed states, update the order status to 'completed'
        $order->update_status('completed');
    }
}

Output

When orders come in from these regions listed in the code(‘KA’, ‘MH’, ‘TN’), they’ll automatically be marked as ‘completed’.

How to Change WooCommerce Order Status for Orders Placed from Certain Regions? - Tyche Softwares


Just as we can customize order status based on specific criteria, like customer states, we can do the same for other factors, such as downloadable products. Check out our post for more details that will change order statuses for downloadable products in WooCommerce.


Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x