Skip to content
Advertisement

Change order status for backordered items in Woocommerce

I am configuring a webshop using WordPress and WooCommerce. I have a plugin installed called Woo Multi Order Creator. What is does is that whenever an order of more than 1 item is made, it divides the main order into multiple orders, one order per purchased item.

Now, what I want to do is to make it change the order status of each order, if the item in each order is containing meta key with the value “Backordered”.

For example if product A and product B are purchased. Product A is in backorder, and therefore has {$wpdb->prefix}woocommerce_order_itemmeta.meta_key = 'Backordered' and product B would be in stock, and it would not have the metakey for backorder.

Now, the thing is that the plugin divides this order into two orders, one per purchased item. What I want it to do further, is to see if the items containted in each new order has the metakey for backorder, and if it has then change the order status to ‘waiting’, for every order.

Plugin code:

JavaScript

It changes the order status to processing at line 253.

I’m guessing that it is around here that a bit of code should be added to make it change order status to waiting instead, if the item in the order has the metakey for backorder.

I hope that someone with more expertise than my very limited knowlegde can come to my assistance.

Advertisement

Answer

Here is a hooked function that is triggered when orders get a “processing” status.

Inside the function we look for order items that are “Backordered” with a simple and light SQL query from the order ID.

If a “Backordered” item is found, we change the order status to “on-hold” (the correct order status for your case).

The code:

JavaScript

Code goes in function.php file of your active child theme (or active theme).

Tested and works.


Update (related to your comment)

If you want to change the code inside the plugin for that purpose, you will replace line 253:

JavaScript

By the following code:

JavaScript

It should work, but this is not a good practice.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement