When selling single products that are also available in bulk packages like 4 packs, 6 packs or 12 packs it may raise some inventory issues. Sure it will work well if all those products are separate and they can’t be split up, but when selling bottles of wine for example its common to be able to order a box of 6 bottles and single ones.

A common used technique within WooCommerce for such products is to use variations of a product to sell the multi-quantity packs of those products. However, the inventory issues will remain with that.

It is possible to enable inventory management on a product level, but this doesn’t deduct the proper quantity when selling a box of 6 bottles, since the customer is in fact just purchasing 1 quantity of it. 

In this post I’m going to show how you can in fact reduce products with a custom quantity for simple product and variations specifically.

Stock Reduction Setting

Lets start by creating a new setting first. Making it available as a simple product and variation specific setting. The following code snippet adds such setting to the products, I’ve written more about adding product settings before here; Adding Custom Product Fields.

With this in place you’ll have a setting in the ‘Inventory’ section and for variable products also a setting per variation.

Reducing Stock with Custom Quantities

Now for the part that actually reduces the custom stock quantities when someone purchases a product. The following code snippet changes the quantity that is used for reducing stock with a sum that multiplies the quantity purchased with the number that is set in our custom setting.

This takes in account when purchasing a variable product to take the variable setting, or when not set it will take the product global setting instead.

Custom Stock Quantities Reduced

As for the end result, lets take this scenario of having these product variations available;

Each variation has the Stock Reduction settings configured accordingly to 1, 6 and 12 reduction per purchased quantity of the variation. The total inventory quantity is set at the product level.

These variations will be presented accordingly on the product page;

Then when ordering a single item of each of those variations, you’ll see that it reduces the custom stock quantities accordingly from the stock level;

Thats it, hope you’ll find this useful!

Jeroen Sormani

I'm a professional WordPress plugin developer on a mission to create the best plugins for my clients. I'm specialised in developing general WordPress, WooCommerce and Easy Digital Downloads plugins.

Interested in talking about a WordPress project? Get in touch!

Follow me on Twitter

61 thoughts on “Custom Stock Quantity Reduction

James October 3, 2019 at 10:20 pm

Is there any wait to make the Variation of a 6 Bottles decrease the Stock Quantity of the Variation for the Single Bottle (i.e. not the Product itself)?

Jeroen Sormani October 3, 2019 at 11:02 pm

Hi James,

Something like this is possible, but I don’t have a ready to go script for this. You’d want to create a customization for that (using this script as a basis).


Richard October 28, 2019 at 3:49 pm

Hello Jeroen

I come back to you because we have an issue somewhere.

We have a product (vitamin bottle) with 2 variations

Duration: 15 days (1 bottle) or 1 month (2 bottles)

Your script is working great as it reduce the stock (-2) when customer choose 1 month variation.

But when we change the order’s status as “completed”, it increase the stock by 1 with no reason.

Any idea?

Thank you

Jeroen Sormani October 28, 2019 at 5:55 pm

Hi Richard,

I’m not sure why that is happening, don’t believe I’ve seen that behaviour before.
Does it reduce the stock correctly when the order is created?

Maybe you have some inventory sync that doesn’t recognise it as buying 2 qty?


Richard November 5, 2019 at 1:40 pm

Hello Jeroen,

Well when the order is paid and created (status “Processing”), the stock is reduct by 2 ( behaviour excepted).

When a manager change status to “completed”, woocommerce recalculate and add a product .

Maybe woocommerce think that this variation is only 1 quantity of this product and not 2 and then correct it when the status/details order page is refresh ?

Thank you

Richard November 5, 2019 at 3:04 pm

To be more specific : When the manager change order’s status or just reload the order details page, woocommerce seem to reajust auto the stock by increasing quantity

Rishi November 13, 2019 at 3:10 pm

Wonderful code! Thank you so much!

I have one issue though. It works great for orders on the front end. But any orders created by an admin form the dashboard don’t seem to honour the multiplier and always reduce quantity by 1. Any idea how to make sure the code works on admin dashboard as well?

Jeroen Sormani November 13, 2019 at 4:25 pm

Hi Rishi,

I’ve not looked into this at this moment. If you’re interested in getting this done as a further customization, please feel free to reach out to me through the contact page.


Gentiel December 3, 2019 at 3:34 pm

Nice, I’m going to try this!

Gentiel December 4, 2019 at 1:39 pm

There seems to be a problem with the ace_custom_stock_reduction function.

Initially it works well but if I change the status of the order afterwards to completed then this happen.

The Custom stock is added back with the difference between the adjusted number and the original number.

How to fix?

David April 28, 2020 at 10:07 pm

Hi Jeroen!
It looks like exactly what i need.
But i get the error :
syntax error, unexpected ‘<', expecting end of file
when i copy -past the code snippet in my theme fonctions.php file through the wordpress editor.
Thanks in advance!

Jeroen Sormani February 9, 2021 at 8:22 pm

Hi David,

This is due to an error with the pasting in the file. I’d recommend reading this post; https://aceplugins.com/how-to-add-a-code-snippet/


John May 6, 2020 at 7:59 pm

I used this code to prevent restocking after a refund.

// remove the restock action
remove_action( ‘woocommerce_restock_refunded_item’, ‘action_woocommerce_restock_refunded_item’, 10, 5 );

Not sure if it works yet.

May November 4, 2020 at 3:37 am

I have the same issue as the people above, when order is placed, the quantity is properly reduced but when the order status was changed from processing -> completed, the stocks increase back.
Order placed: -5
Order changed from processing to completed: +4

How do we fix this? Thank you

Jeroen Sormani February 9, 2021 at 8:18 pm

Hi May,

The snippet was just updated to solve this odd stock change on order change.


Chris December 12, 2020 at 12:00 am

This was an amazing help on how to edit the item inventory levels! Worked great for me on WP 5.6!

Igor Ilgiyaev January 17, 2021 at 2:30 pm

Is it working on simple products too? from what I have check it’s not or maybe not working on WOO 4.8.x.

Jeroen Sormani February 9, 2021 at 8:13 pm

Hi Igor,

It was designed for variations, but it is possible to modify the custom script further to fit it for simple products as well.


Complexy February 6, 2021 at 10:20 pm

Same problem here. When the order status change variation stock works as usual.

How to fix?

Jeroen Sormani February 9, 2021 at 8:12 pm


I’ve just reviewed the customization and added a change that fixes the stock change after a order update.


Chris February 15, 2021 at 12:33 am

Just wanted to add to the general sentiment and say many thanks for this. Spent all day banging my head against a wall trying to find a plugin that would do this, and here we are.

On top of that, I also learned how to create and edit a child theme, so thanks for improving my knowledge as well.

Lastly, just to reiterate what a couple of people have said – it would be perfect if we set variations as out of stock if the product inventory level was below that quantity! (i.e. I have an option for a customer to buy 1 or 2 of an item. Currently I have 34 in stock, so that’s fine, but when I just have 1 left, then it would be great if the ‘2’ option was shown as out of stock somehow!

Thanks again,

Gilbert March 13, 2021 at 4:37 pm

Thanks Jeroen. Great job. Very much appreciated!

Pixolomew March 23, 2021 at 12:40 am

Spent about three days looking at solutions to this problem, this worked perfectly, thank you!

John S. April 16, 2021 at 7:07 pm

Thank you, Jeroen. This helped a lot!

Blessing September 25, 2021 at 1:09 am

Thank you, Jeroen. This was helpful for my case

Laurent October 28, 2021 at 10:11 am


Is there a way to let the frontend validate the available stock too based on this stock multiplier value?

Given the following situation:
– Shop has 10 bottles of wine in the inventory
– Customer wants to order 2 crates of 6 bottles.

We have something similar in our webshop, but now customers are able to order 2 crates while there aren’t enough bottles to ship 2 crates.


Jeroen Sormani October 31, 2021 at 4:05 pm

Hi Laurent,

This snippet is currently not that advanced, but a check like that can be added to add to the customization.


Ian May 4, 2022 at 11:51 am

Hi Jeroen would this work if we wanted to sell an item that’s normally a pair but we want to sell 3 would the adjustment work?

Example 1 x pair of hinges but customer needs three so they order 1.5.

We could sell them as individual items but they are packed in pairs so then we would need a min order of 2

Jeroen Sormani May 4, 2022 at 1:53 pm

Hi Ian,

This could work if you sell / stock them as individual items (a customization can be used so minimum order quantity is 2). If you stock the product as 1 = a pair then it would be more difficult. This would then require that your store supports stock and purchases of .5 quantities (which isn’t possible out of the box).


Leave a Reply