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

4 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.

Cheers,
Jeroen

Ricardo October 20, 2018 at 1:36 pm

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

Leave a Reply