How to change WooCommerce order status programmatically

This article will help you to change order status for WooCommerce orders programmatically. It will also teach you to get order status details for WooCommerce orders.

WooCommerce order status is an important meta field that stores the order statuses of a customer’s order. The status could be viewed in the frontend and backend of your website via “My Account” area in the account dashboard of your WooCommerce store. It is generally used to indicate the current state of the order. In this tutorial, we will show you how you can change WooCommerce order status programmatically using some PHP code.

woocommerce change order status programmatically

It is very easy to change or edit the order status in WooCommerce dashboard. All you have to do is go the the specific order in your WooCommerce -> Orders section open the specific order and click the status drop down to select the new order status.

However this works only on a single order basis, what about if you have thousands of orders that you need to change the order status of. If you want to change the status in bulk, there’s no way of doing so without some pretty complicated code or dedicated WordPress plugin. Or if you are trying to automate the change in order status from “on-hold” to “pending payment” or some other custom order status once a product vendor has marked an order as fulfilled for example. It it possible to update to the “pending” status after an action has been made with some custom code.

You can change the order status of a WooCommerce order programmatically using the WC_Order class. Call the function with correct parameters and it should work for you:

$order = new WC_Order($order_id);

if (!empty($order)) {

$order->update_status( ‘completed’ );


Possible order status values: processing, on-hold, cancelled, completed. If you have created your own custom status via code or dedicated WooCommerce plugin you should be able to change the order status to one of those particular status.

You can find more details about it here: WooCommerce Code Reference.

Make sure that you add the code snippet to your WordPress child theme functions.php file or if you have a dedicated snippet plugin you can add it in there instead.


WooCommerce allows you to create your own customized store and sell products online and it has tons of functionality that can be extended by utilising the API. In this tutorial we looked at updating the order status programmatically to a new status in an automated and dynamic way.

Unlock the Full Potential of Your WooCommerce Customer Data