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

48 thoughts on “Custom Stock Quantity Reduction

Adam Davies September 27, 2018 at 1:56 pm

This is amazing and exactly what I was looking for. Should be built into Woocommerce in my opinion. Thanks again ๐Ÿ™Œ

Neville White October 16, 2018 at 6:00 pm

Hi Jeroen

Thanks very much for this very clever Custom Stock Quantity Reduction code. Greatly appreciated. I have been experimenting with it and it indeed reduces the stock as described. Do you know a way to tweak it so that unavailable quantities are hidden or marked as out of stock to prevent them being ordered? For example if there are 8 bottles left in stock, the 1 and 6 bottle options should be available but not the 12 bottle option.

Jeroen Sormani October 16, 2018 at 7:42 pm

Hi Neville,

Thats a good question.. I haven’t looked into that myself, but should be possible to do.
What I’d recommend doing is having your webdeveloper assist with that customization (feel free to reach out to me if you don’t have a developer/would like to discuss this) – I can’t really do it within this blog post.


Ricardo October 20, 2018 at 1:36 pm

Thank you man , you’re my savior ๐Ÿ˜‰

Hamid January 5, 2019 at 3:39 pm

I find it very helpful mate, Thanks for saving my time with that solution ๐Ÿ™‚

Doug Chandler January 16, 2019 at 5:33 pm

This is exactly what I am looking for…

Doug Chandler January 16, 2019 at 6:09 pm

Would love to know if you got some code snippet to check the stock levels too for each variation?
I am really surprised this is not in the base product, seems common sense to me…

Alejandra Bernal January 26, 2019 at 5:37 am

Hello Jeroen! Its exactly what i was looking for. But now i have the same problem that Neville, i need to show the items as not available to prevent people to order them.
Could you help me with that? i’ve been trying but i can’t get the right code.

Thank you!!

Dave March 11, 2019 at 11:24 am


Can this snippet be made to reduce inventory of the parent SKU of the variable product rather than reducing inventory for each variant?


Jeroen Sormani March 11, 2019 at 2:30 pm

Hi Dave,

That is exactly what this blog post is describing.


Scott April 1, 2019 at 7:28 pm

Bingo!!! Genius work.

Bod April 23, 2019 at 10:07 pm

You are a life saver. Please is it possible get a code snippet that reduces purchased quantity from all products within a category. I have a shop where we sell shirts with different designs, each of these different designs are set up as separate products, so for example we have about 50 black shirts in stock, when a customer purchases 3 shirts of design A, I want all the other designs’ stock to reduce to 47pcs because in reality our black shirt stock has reduced to 47pcs. I guess All black shirts should be tied to the same category for this to work.

Please any help will be greatly appreciated.

Jeroen Sormani April 24, 2019 at 9:52 am

Hi Bod,

I don’t have something ready to go for reducing stock category wide based, but if you’d need some help I’d be happy to make my personal ask for it.
Feel free to reach out; https://jeroensormani.com/contact/


Philip Stancil May 6, 2019 at 10:19 pm

Thanks so much for sharing this, man! Should def be part of WC core.

Jason Breens May 11, 2019 at 11:33 am

Much appreciated! Quick question..Do I add an SKU for the parent inventory, and DIFFERENT SKU’s for the variations?

Jeroen Sormani May 13, 2019 at 10:34 am

SKU is not related for this snippet

Scott May 13, 2019 at 9:25 pm

Hey Jeroen, this was working great, until I updated Woo to 3.6.2. For example, items where parent stock was 500, and pack inventory value was 50 or 100, resulted in OUT OF STOCK. After much testing, I discovered that editing the parent Stock Quantity (from 500 to 501) was the only way to return to normal, expected functionality. Could this be related to code, or some kind of transient type issue?

Merissa May 26, 2019 at 7:19 am

This is AMAZING! Exactly what I needed. Thank you so so so so much for this code!

Stephanie Graham June 11, 2019 at 11:14 pm

This is exactly what I am looking for, however, I am not a developer and not comfortable with editing code. If you make this into a plug in, I could use that! It sure looks like it’s working pretty well.

Jeroen Sormani June 12, 2019 at 9:29 am

Hi Stephanie,

I wrote a blog post on adding custom code snippets here; https://aceplugins.com/how-to-add-a-code-snippet/
If you’re not comfortable doing that either you can also get it done for you.

Joel July 23, 2019 at 1:17 am

One comment on this otherwise awesome post. Is there any issues with cancelling the order, will the proper amount of product be returned upon a cancel. Had a plug-in that did this exact thing but the cancellations weren’t being returned to inventory properly.

Jeroen Sormani July 24, 2019 at 11:03 am

Good question; I haven’t tried refunds/returns yet, but I’d imagine they’d indeed not automatically be increased by the multiplier amount.
The code can of course be used to build further upon to include that as well.

Henrik July 23, 2019 at 4:15 pm

Thank you so so so so much for this code! Exacly what I needed

Scott August 9, 2019 at 5:39 pm

Hey Jeroen, have you ever looked at tackling low stock threshold for variants? For apparel shops, this is a big missing feature of Woocommerce. For example, we never keep medium shirts in same quantity as 5XL. Mediums out-sell 5XL by many multiples.

Jeroen Sormani August 12, 2019 at 11:11 am

Hi Scott,

Never looked into that – interesting thought though and shouldn’t be too difficult to do with a custom script.


Nicole August 12, 2019 at 6:07 am

I sell fruit and veg online (in quantities of single, 500g and 1kg)

This is EXACTLY what I needed – thank you so much Jeroen!

Talels October 3, 2019 at 7:30 pm

You are incredible, awesome code

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,

Leave a Reply