Search the site:

Home Blog How to create custom WooCommerce Order Statuses

How to create custom WooCommerce Order Statuses

Orders are created in WooCommerce when a customer completes their checkout process. WooCommerce orders have different statuses which lets you know the current position of the order, whether it is complete or its payment is pending, etc.

WooCommerce has few pre-defined order statuses which helps us to move the order from one stage to another in the processing cycle. Let’s have a look at them.

Pending Payment:

The order status is set to pending payment when the order is placed but the payment is not made. This normally occurs when ‘Cash on Delivery’ is selected as the payment option.

Processing:

The order is set to the status of processing when the order is placed and payment has been made and the stock is also reduced. All orders go through processing except ‘Downloadable’. The downloadable items are made available once the payment has been made by the customer.

Completed:

Once the order is placed, payment has been made and order is delivered to the customer, the order is marked as completed. The order requires no further action.

On-Hold:

The order is set to the status of on-hold when the order is placed and payment is awaited. The stock is reduced once the order is set to on-hold. The admin needs to confirm the payment. Generally, if the order is of digital & downloadable products, the status is set to on-hold. Once the payment is made, the digital products are sent to the customer and the order is marked as completed.

Cancelled:

The order status is set to cancelled if the customer or admin cancels the order. The stock is not reduced here.

Refunded:

The payment has been refunded to the customer by the admin if the order was cancelled.

Failed:

The order status is set to failed if the payment process failed during the checkout or payment was declined.

Creating a Custom Order Status

Now that we have looked at the available order statuses, let’s create a new custom order status. It’s possible that you want to create a new order status that doesn’t belong to any of the current order statuses. That’s a very common business requirement of WooCommerce store owners.

Order statuses are stored in the  post_status column in wp_posts table. So, we first need to register a post status using register_post_status method available in WordPress.

For example, our Deposits for WooCommerce plugin has a custom order status of Scheduled. The scheduled orders are created when the user selects a payment plan and the remaining deposit amount is to be paid through subsequent orders. These orders have the order status of Scheduled.

Let’s create an order status called ‘Scheduled‘, which will be stored in the databases as ‘wc-scheduled‘ post status.

In the above example, we register a new post status using register_post_status(). The function takes two parameters – $post_status and $args. $post_status is the name of the new status that should be stored in database whereas $args parameter is an array which has following properties –

  1. label: A name for the post status
  2. public: Whether posts of this status should be shown in the front end of the site
  3. exclude_from_search: Whether to exclude posts of this status from the search results.
  4. show_in_admin_all_list: To include posts in the edit listing of their post type
  5. show_in_admin_status_list: Show in the list of statutes with their post counts.
If you are not well versed with coding now you can add new custom order statuses easily without doing any code changes using our Custom Order Status for WooCommerce plugin:

 

Now we need to add this post status in the array of the order statuses. We can do this by using the WooCommerce filter – wc_order_statuses. This function takes one parameter – $order_statuses. We add our new post status in the array and return the new array.

The order status will now show up on the edit order page –

As we have set the show_in_admin_status_list property to true, it will also show up in the list of filters on the WooCommerce Orders page if you have any order with order status of wc-scheduled.

And if you look in the wp_posts table, you can see the post status of the order is saved as ‘wc-scheduled‘.

As you can see, it is quite easy to create a custom order status in WooCommerce. Common examples of custom order status will be – scheduled, shipped, awaiting shipment, etc. I hope you find this useful and always eager to hear back from you.

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

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
1 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Charles Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest
Notify of
Charles
Guest

The code works great, thank you. But under the new created order status (for us it’s “proforma”) the order is ” This order is no longer editable.”
Would you know how to keep the order editable under the new custom status? Thanks

from purchased

Subscribe for more offers