How to Make Variation Shared Inventory on your Store
In this tutorial, we will discuss WooCommerce stock management for variations. Specifically, I want to share with you different approaches to setting up a shared stock for WooCommerce product variations.
The common ways of implementing a variation shared stock are:
- Using the shared stock for all variations of a specific product.
- Assigning the same SKU for specific variations (doesn’t matter whether they belong to the same product or different products) and reducing stock for all variations with the same SKU synchronously. This approach can be implemented with the plugin.
- Combining specific variations into a group, and if any variation from the group has been purchased, we will reduce the stock levels of the whole group.
- Assigning a stock quantity to a specific attribute and then managing the inventory on the attribute level.
For most of the ways mentioned above, I will show you the programmatic approach (with a code snippet), except for the one that will require the use of a WordPress plugin.
Now, let’s dive straight into it.
Method 1. Shared Inventory for All Variations of a Product
This is the easiest way, and it can be accomplished without any plugins or custom coding – just with standard WooCommerce settings.
I’m mentioning it first because maybe that’s what you need, and you don’t need to dive deep into more complicated solutions.
So all you need to do is go to the edit product page and then to the “Inventory” tab:

One more thing, if you go to any specific variation of this product, check the “Manage Stock?” checkbox, and set stock levels individually for this variation, then the shared stock quantity is not going to be applied to this variation:

As you can see, these standard WooCommerce settings are pretty neat, so you probably don’t even need to look into the other solutions described in this tutorial, because basically, to make a shared stock for a variation group, you just need to do two things:
- Allow stock management on a product level (first screenshot),
- Exclude specific variations by managing the stock individually for them (second screenshot).
As simple as that.
Method 2. Shared Stock for Variations with Duplicate SKUs (Using a Plugin)
Let’s take a look at another solution for configuring the variation shared inventory for WooCommerce stores.
If you think that combining variations into groups and managing stock on the attribute level is kind of complicated for you, you can just provide the same SKU for variations you would like to have a shared inventory (and these variations do not necessarily have to relate to a single product).
It can be achieved easily with my Duplicate SKU Stock Sync plugin.
What is interesting about the plugin is that it simply works out of the box; you don’t even need to configure anything, just activate it, and that’s it – product variations with the same SKU will share the same stock.

However, in the recent version of the plugin, you can configure SKU mapping rules, for example, if you want variations with the same SKU but with different prefixes or suffixes to share the same stock.
Method 3. Shared Inventory for a Group of Variations
First of all, what is a group of variations?
Well, it could be a bunch of variations for which you decided that their stock quantity should be the same.
For example, in the code below, I decided that my group would consist of 3 variations, and I hard-coded them this way array( 5, 15, 254 ). Of course, when you’re creating a WordPress plugin or a client project, nothing should be hard-coded like this, and it is up to you to decide how you want to manage variation groups on your WooCommerce store.
/**
* @snippet Variation Shared Inventory for WooCommerce (Group of Variations)
* @author Misha Rudrastyh
* @url https://rudrastyh.com/woocommerce/variation-shared-inventory.html#group-of-variations
*/
add_action( 'woocommerce_variation_set_stock', 'rudr_grouped_variation_stock' );
function rudr_grouped_variation_stock( $variation ) {
// $variation is a WC_Product_Variation object
// get updated inventory information
$stock_status = $variation->get_stock_status();
$stock_qty = $variation->get_stock_quantity();
// let's get a group of this variation
// you can store it the way you like, I am just proviging IDs statically
$group = array( 5, 15, 254 );
// let's get a parent product, so we can get other variations
$product = wc_get_product( $variation->get_parent_id() );
// get all variations (both enabled and not enabled)
$variation_ids = $product->get_children();
remove_action( 'woocommerce_variation_set_stock', __FUNCTION__ );
foreach( $variation_ids as $variation_id ) {
if( ! in_array( $variation_id, $group ) ) {
continue;
}
$variation = wc_get_product_object( 'variation', $variation_id );
$variation->set_stock_status( $stock_status );
$variation->set_stock_quantity( $stock_qty );
$variation->save();
}
add_action( 'woocommerce_variation_set_stock', __FUNCTION__ );
}What I want to highlight in this code example:
- As you can see, I used
get_children()method to get all product variations, this method allows you to get both enabled and not enabled ones, but if you only want to get the variations that are available for purchase, then useget_available_variations()instead (and we’re going to use it in the next example). - We also need to use
remove_action()for thewoocommerce_variation_set_stockhook because it will be fired whenever we change a variation stock quantity programmatically. So the whole thing may end up in an infinite loop. - To get a variation object, you can use the
wc_get_product()function, thewc_get_product_object()function (we used it) ornew WC_Product_Variation().
I think we’re done here. Now, let’s configure the variation shared inventory in WooCommerce another way – using attribute stock levels.
Method 4. Attribute Stock Management
Let’s assume that you have a bunch of variations, like in a screenshot below, and you would like variations with the same color attribute to have a shared stock; in other words, we need to manage stock on the attribute level in this case.

#39 or #34, the stock will be changed for them both./**
* @snippet Variation Shared Inventory for WooCommerce (Attribute Stock)
* @author Misha Rudrastyh
* @url https://rudrastyh.com/woocommerce/variation-shared-inventory.html#attribute-stock
*/
add_action( 'woocommerce_variation_set_stock', 'rudr_attribute_stock' );
function rudr_attribute_stock( $variation ) {
// get updated inventory information
$stock_status = $variation->get_stock_status();
$stock_qty = $variation->get_stock_quantity();
// let's get a parent product, so we can get other variations
$product = wc_get_product( $variation->get_parent_id() );
// get all variations (enabled)
$variations = $product->get_available_variations();
remove_action( 'woocommerce_variation_set_stock', __FUNCTION__ );
foreach( $variations as $variation_data ) {
if(
! isset( $variation_data[ 'attributes' ][ 'attribute_pa_color' ] )
|| 'blue' !== $variation_data[ 'attributes' ][ 'attribute_pa_color' ]
) {
continue;
}
$variation = new WC_Product_Variation( $variation_data[ 'variation_id' ] ));
$variation->set_stock_status( $stock_status );
$variation->set_stock_quantity( $stock_qty );
$variation->save();
}
add_action( 'woocommerce_variation_set_stock', __FUNCTION__ );
}Here, I’ve also hard-coded a condition when we check the value of the attribute_pa_color attribute (which is “Color”), and we’re making sure that its value is blue. Once again, ideally, nothing should be hard-coded, so please consider adding some settings for it, for example.
Misha Rudrastyh
Hey guys and welcome to my website. For more than 15 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Your blog is so useful to me. Thank you very much!
🙂🙏
Great article. I’ve had this problem for years, but my biggest problem is I need certain variations to remove a set amount of inventory. For instance I have 100 pens. I sell 10-20-30 packs.
Need the inventory of 100 pens to auto-split itself between the inventory. 10 – 10 packs. 5 – 20 packs. and 3 – 30 packs.
Then as someone buys, each level adjusts itself. Found ATUM to work pretty well, but it has so many useless features. Gonna try tinkering with option 3 a little bit and see if i can get any different variation working.
thanks for the great guide!
Yes, some of my clients are using ATUM as well.
Thank you for sharing your scenario! I can not personally advise you to read an article on my blog or a plugin, but I will take a look at it when I have time.