How to Sync Stock Across Multiple Stores in WooCommerce

In this guide, I will show you how to implement a multi-store WooCommerce stock synchronisation (for products with the same SKU, slug, or “GTIN, UPC, EAN, or ISBN” field).

We will use two different approaches to achieve that:

Let’s get started.

But before we start – one more thing. If your goal is to sync stock for products with the same SKU within the same WooCommerce store, you probably need a different solution; in that case, the Duplicate SKU Stock Sync plugin is what you would need.

Using “Inventory Sync for WooCommerce” Plugin to Sync Stock Across Multiple Stores

In the examples below, we will be using the Inventory Sync for WooCommerce plugin.

However, you don’t have to hurry up and activate the plugin for all your WooCommerce stores, because it may not be necessary – it’ll all depend on the goal you’re trying to achieve. I will try to cover all possible scenarios in the examples below.

There is also a free version of the plugin in the WordPress.org plugins repository.

Example 1. Syncing stock from one store to another

The easiest scenario is when you need stock changes on “Store 1” to be automatically reflected on “Store 2”.

For example, when:

  • an administrator or a ship manager updates a specific product’s stock quantity manually, via the WordPress admin dashboard,
  • an order is being placed by a customer.

In both of these, you want the plugin to find appropriate products (with the same SKU, or slugs) on “Store 2” and update their stock quantity as well.

How to configure the Inventory Sync for WooCommerce plugin for that scenario?

StoreAction
“Store 1”The plugin should be installed, and “Store 2” needs to be connected in the plugin settings.
“Store 2”

This is how to connect “Store 2” in the plugin settings page:

WooCommerce stock sync to another store
WooCommerce > Settings > Products > Inventory Sync

Example 2. Two-way inventory sync between two stores

This scenario is very similar to the previous one; the only thing you need to do is to connect stores to each other, in both ways, I mean.

Here is how it should be configured:

StoreAction
“Store 1”The plugin should be installed, and “Store 2” needs to be connected in the plugin settings.
“Store 2”The plugin should be installed as well, and “Store 1” needs to be connected in settings.

Example 3. Implementing central stock in WooCommerce

This is a more interesting scenario. The idea is to have a main store, where the stock from multiple sub-stores is managed. The main question we may ask here is whether the stock should be synced to other sub-stores when it is updated on a specific sub-store, or, in reality, do sub-stores have different products?

Actually, I have a separate article where we implemented central stock for WooCommerce step by step.

StoreAction
“Store 0” (Central Stock)The plugin should be installed, and “Store 1”, “Store 2”, and “Store 3” need to be connected in the plugin settings. In case the stock changes that happen on a sub-store (let’s say, “Store 2”) should be automatically reflected on other sub-stores (“Store 1” and “Store 3”), then the “Sync chain” option should be activated as well in the settings.
“Store 1”, “Store 2”, “Store 3”The plugin should be installed, and “Store 0” (Central Stock) needs to be connected.

This is how the plugin settings page will look for your central stock WooCommerce store:

WooCommerce stock sync multiple stores
The stores connected in the stock sync settings in “WooCommerce > Products > Inventory Sync” for the main store, which serves the purpose of the central stock.

For “Store 1”, “Store 2”, “Store 3”, it will be the same:

Configure central stock for WooCommerce

Example 4. WooCommerce Multisite stock synchronisation

The inventory syncing process between sub-sites of a WooCommerce multisite network is not that different than syncing stock across multiple stores, which are not managed under the same multisite network.

The differences are:

  • The plugin must be network-activated.
  • The store connection is super-easy; you just need to select the sub-store you need from the dropdown list, instead of dealing with the REST API credentials (a consumer key and consumer secret).

Example of connecting a store in a WordPress Multisite (or WooCommerce Multisite) network:

Connect a store to sync stock in WordPress Multisite
WooCommerce > Settings > Products > Inventory Sync

Of course, stock sync across multiple stores, which are a part of the same WordPress multisite network, significantly wins in performance compared to doing the same for standalone stores, because we don’t need to send multiple requests to the WooCommerce REST API; in other words, everything is happening on the same server, for the same WordPress installation.

Sync Stock Multiple Stores – Programmatic Approach

If you decide to go with the programmatic approach, then you need to keep in mind that there are two scenarios you will need to process in your code:

  • Scenario 1. When a product is updated manually (by an administrator or a shop manager, for example).
  • Scenario 2. When an order is being made by a customer.

The good news is there are a bunch of WordPress/WooCommerce hooks that you can use:

Hook nameDescription
woocommerce_product_set_stockA product’s stock is updated (doesn’t matter how, but may not be covering third-party plugins).
woocommerce_variation_set_stockA product variation’s stock is updated.
save_post_productMust be considered if your goal is to trigger stock sync only when a specific product or variation is updated via the admin dashboard.
woocommerce_reduce_order_stockWhen an order is placed (isn’t triggered for all order statuses, by the way).
woocommerce_restore_order_stockWhen an order changes its status to some specific statuses.

The bad news is that for the second scenario, when an order is being made, we must take into consideration that there could be orders with a lot of products and variations at the same time (I am talking hundreds). So, basically, we can not simply send REST API requests one by one, because our customer will never get to the “Thank you” page. The solutions are:

  • using Action Scheduler to sync the stock in the background,
  • combining REST API requests in batches,
  • processing the requests with the PHP Requests library when necessary.

By the way, the full version of the Inventory Sync for WooCommerce plugin is doing all of that, but since we’re talking about the programmatic way of doing things, I just had to mention that. Now, let’s take a look at the stock sync PHP function:

// sync stock of a product with the same SKU on another WooCommerce store
function rudr_sync_product_stock_another_store( $product_id ) {

	$product = wc_get_product( $product_id );
	
	// since we connect products by SKU, we need to check that first
	if( ! $product->get_sku() ) {
		return false;
	}

	// credentials to connect via WooCommerce REST API
	$store_url = '';
	$consumer_key = '';
	$consumer_secret = '';

	$woocommerce = new Client( $store_url, $consumer_key, $consumer_secret, array( 'version' => 'wc/v3' ) );

	try {
		// first of all we need to find a product on "Store 2" with the same SKU
		$products = $woocommerce->get(
			'products',
			array(
				'sku' => $product->get_sku(),
			)
		);

		if( empty( $products ) ) {
			return false;
		}

		$remote_product = reset( $products );

		// now, we can update stock information
		$woocommerce->put(
			'products/' . $remote_product->id,
			array(
				'manage_stock'   => $product->get_manage_stock(),
				'stock_quantity' => $product->get_stock_quantity(),
				'stock_status'   => $product->get_stock_status(),
			)
		);

		return true;

	} catch( Exception $error ) {

		// here we can use WC_Logger class to log error messages
		return false;

	}

}

As I already mentioned before, it is up to you to decide which action hook you want to connect this function to.

If you have any questions or suggestions, please let me know below 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