Setting Up Shared Stock in WooCommerce

In this guide, I will show you multiple methods of setting up shared stock (shared inventory) for specific products in your WooCommerce store (or stores).

But first of all, there are two completely different WooCommerce configurations, and we will uncover both of them in the tutorial below:

  1. Different products within a single WooCommerce store share the same stock – we will talk about this configuration in the first part of the tutorial.
  2. Products across different WooCommerce stores should have a shared stock set up. The stores actually can be sub-stores within a single WooCommerce Multisite network or completely standalone stores – it doesn’t matter here. Usually, the goal of this approach is to manage stock in one central location. This is what the second part of the guide is about.

Let’s dive into it.

Scenario 1. Shared Stock Between Specific Products in a Single WooCommerce Store

First of all, let’s decide how we should define the products that should share the same inventory within a WooCommerce store. The following ways come to my mind:

  • Products with the same SKU (I know that originally, WooCommerce doesn’t allow duplicate SKUs, but it can be allowed pretty easily).
  • Products with the same attribute.
  • Product relations are set up in the code.
  • Variations of the same product – I have already uncovered it in my other tutorial.

Let’s walk through each of the ways step by step.

Shared inventory for products with the same SKU (using a plugin)

Of course, you can always create a WooCommerce options page where all products that should have shared stock can be specified. However, this page’s interface can be quite complicated, especially if we want to have multiple pairs of products with the same stock.

What is the solution here?

We can use the same SKU for different products, ones that we want to share the same stock.

In that case, we don’t even need extra configuration; all we need to do is install and activate the Duplicate SKU Stock Sync plugin for WooCommerce.

Configure the shared stock for WooCommerce products with the same SKU

Of course, you might have some logical questions about the plugin:

  • Wait, but WooCommerce doesn’t allow the use of the same SKUs for multiple products? That’s correct, but my plugin automatically removes this restriction.
  • What if I want to use prefixes or suffixes for my SKU? For example, “SKU-NL”, “SKU-DK”, “SKU-SE”, etc and I want the plugin to treat these products as the same? It is also possible with the new feature – SKU mapping rules.

If you have any other questions related to the plugin, feel free to ask in the comments below.

Setting up product relations programmatically

The whole idea is pretty simple here and can be broken down into three steps:

  1. deciding about which products are going to have the same stock levels,
  2. creating a custom function connected either to the woocommerce_product_set_stock or to the woocommerce_variation_set_stock action hook if we are talking about variations.
  3. setting the stock levels of the products using set_manage_stock(), get_stock_status(), and get_stock_quantity() methods of the WC_Product class.

Below is the code snippet you can insert into your WooCommerce store:

add_action( 'woocommerce_product_set_stock', 'rudr_update_shared_stock' );

function rudr_update_shared_stock( $product ) {

	$new_manage_stock = $product->get_manage_stock();
	$new_stock_status = $product->get_stock_status();
	$new_stock_qty = $product->get_stock_quantity();

	// we have to get the connected products
	$products = array( 15, 21, 25 ); // let's say we have product IDs here

	if( ! $products ) {
		return;
	}

	remove_action( 'woocommerce_product_set_stock', __FUNCTION__ );
	foreach( $products as $product_id ) {

		$product = wc_get_product( $product_id );
		if( ! $product ) {
			continue;
		}

		$product->set_manage_stock( $new_manage_stock );
		$product->set_stock_status( $new_stock_status );
		$product->set_stock_quantity( $new_stock_qty );
		$product->save();

	}
	add_action( 'woocommerce_product_set_stock', __FUNCTION__ );

}

Some moments to consider:

  • We have the WC_Product object available as the $product argument, which is amazing.
  • You can provide the ID of the products that should have the shared stock as an array in the $products variable. If you don’t like the hard-coded approach, you can create a WooCommerce settings page for this purpose.
  • It is also quite crucial to remove the woocommerce_product_set_stock hook inside the function using the remove_action() function, otherwise, it will be looped, and you will get an error 500, thanks to $product->save().

Attribute-based shared stock

Let’s say we have a product with an attribute “Color” pa_color set to “Blue” blue and when this product is purchased, we want to reduce the stock levels for all the other products in our WooCommerce store with the same attribute value.

This solution for WooCommerce products can be a little bit complicated, so I decided to skip this part; however, there are two things:

Scenario 2. Sharing Product Stock Across Multiple WooCommerce Stores

What if you either have:

  • two WooCommerce stores, and you need the product stock to be synced between the same products in these stores,
  • or multiple WooCommerce stores (any amount), and you need the product stock to be synced into a central location and to be managed there.

In either case, you need to have a connection between the target stores somehow.

In WooCommerce Multisite, it doesn’t seem so complicated; we just need to use the woocommerce_product_set_stock filter hook again, the switch_to_blog() function, and the wc_get_product_id_by_sku() function, I guess. But if you’re using a standalone store, the situation becomes more interesting, since now you need to use the WooCommerce REST API. Plus, everything becomes twice as complicated since we are talking about not only updating the products via the WooCommerce admin dashboard but also reducing stock levels when an order is placed by a customer. I’d like to remind you that an order can contain tens of products, and sending too many API requests will significantly increase the loading time of the “Thank you” page and will ruin the customer experience.

What is the solution here, again?

If you were looking for a programmatic approach, I could suggest my other tutorial. But as I said before, if you decide to go the programmatic way, you will need to keep in mind many things if you want your custom functionality to work smoothly and without issues.

My recommendation is to check the Inventory Sync for WooCommerce plugin.

It allows you to set up shared stock for your WooCommerce products in minutes.

Basically, what you need to do:

  1. Decide, in the plugin settings, whether you want the same products across stores to be identified by SKU (by default) or by slug.
  2. Connect stores in the plugin settings. If these stores are within a single WooCommerce multisite network, then you only need to select them; otherwise, use Consumer Key and Consumer Secret (the REST API authentication data) to establish a store connection.

Below, in the screenshot, you can see how the stores can be connected in settings:

Shared product stock between different WooCommerce stores
Two-direction stock synchronization is also possible; in that case, the plugin should also be installed on “Store 2” and “Store 1” should be connected in the settings.

That’s pretty much it.

If you have any questions, feel free to ask in the comments.

Misha Rudrastyh

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

Follow me on X