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

Ian May 10, 2022 at 10:45 am

Thank you Jeroen

We might have to have a think on the best solution for this then.

Cheers Ian

Vagos June 15, 2022 at 9:49 pm

Hello

I love this !
Is there any way to change the display of stock quantity depending on the variation that is choosen ?

Tomasz September 12, 2022 at 6:55 pm

Thank you Jeroen! This is a very good job. But I found bug… When have I low stock in shop, customer can buy more than I have in stock…
Example:
I have only 1 wine of bottle in stock.
Customer bought 6 bottle.
Stock is -5.

Jon June 26, 2023 at 5:01 am

Does this snippet only apply settings to products where a value is specified? In other words, if it is left blank the default value of 1 stock quantity will be reduced in the inventory. Is that a correct assumption?

Jeroen Sormani June 26, 2023 at 10:21 am

Hi Jon,

That is correct.

Cheers,
Jeroen

Leave a Reply