Multisite Product Sync for WooCommerce

Below, I will show you two ways of configuring WooCommerce multisite product sync between stores within a single WordPress multisite network – with the Simple Multisite Crossposting plugin and without any plugins as well.

But please keep an important thing in mind – if you’re not using your WooCommerce stores as part of a WordPress Multisite network (or maybe you’re just not exactly sure what it means), then check this article instead. Though the idea and the process will be similar in that case, the tools and functions in the code will be completely different.

Using a Plugin – Simple Multisite Crossposting

Let’s start with the plugin approach first. We will use Simple Multisite Crossposting for that. First of all, install and network activate the plugin for your WordPress Multisite.

Then, when editing a product, select target stores where you’d like to sync this product:

WooCommerce multisite product sync
Select WooCommerce sub-stores with which you need to sync this specific product.

Multiple products can also be synced together with bulk editing:

Using bulk editing to sync multiple WooCommerce products at the same time.

In case you were wondering whether the plugin allows you to sync all the necessary product data or not, here is what is supported:

  • All the basic product data, like product name, slug, description, short description, status, catalog visibility, publish and modified dates.
  • Product prices (sale prices, sale dates).
  • Inventory information (stock status, quantity, etc).
  • SKU and GTIN, UPC, EAN, or ISBN fields.
  • Product images and gallery images.
  • Product shipping information (weight, dimensions, shipping classes).
  • Related products (Upsells, Cross-sells, etc).
  • Downloadable products.
  • Attributes.
  • Variations with all their data for variable products.
  • Product categories, tags, brands, and custom taxonomies. Also, when working with WooCommerce product category sync, it is also possible to include all the data from categories, like category images, description, custom fields, etc.
  • Custom fields (created with ACF, with another third-party plugin, or manually).
  • Languages (created with WPML or Polylang).
  • etc.

However, if you’d like, you can exclude any specific product data from syncing in the settings, in the “Fields” tab. For example, if you need the products to have separate stock or different prices across different stores, or to not sync related products. You can see an example in the screenshot below:

Configure what WooCommerce product data should be synced in the plugin settings
We excluded “Stock” from syncing because we want the products to have separate stock across sub-stores in a WooCommerce multisite network.

The product connection between stores happens by SKU by default, because it is the fastest and the most mistake-free way, but you can change it in the settings and connect shared products by a meta field.

Feel free to use my Simple Multisite Crossposting plugin to configure WooCommerce multisite product sync on your stores without touching a single line of code.

That’s pretty much it with the plugin approach, and I’m going to dedicate the rest of the tutorial to the programmatic approach.

Creating WooCommerce Multisite Product Sync in Code

Now, let’s do it fully programmatically, with the help of the woocommerce_update_product action hook, the switch_to_blog() function and CRUD layers (once again, in case we’re working with standalone WooCommerce stores rather than with a multisite network, then we need to use the REST API instead; there is a separate article about that).

1. Automatically publish products on another store

Let’s assume that we have “Store 1” and “Store 2” as part of a WordPress multisite network, and when a product is created on “Store 1”, it should be automatically shared on “Store 2” as well.

We all know save_post andsave_post_product action hooks, but should we use them here? Perhaps we can look towards the woocommerce_update_product hook that appeared in WooCommerce 3.0, because at least you will have the whole WC_Product object available as its second argument. There is also the woocommerce_new_product hook, but it is not going to be activated when you create a WooCommerce product from the admin dashboard. So, let’s stick to the woocommerce_update_product hook for now.

Also, my tutorial about creating products programmatically might be helpful here. For the simplicity of the code, we are going to work with simple products only.

add_action( 'woocommerce_update_product', 'rudr_crosspost_product', 20, 2 );

function rudr_crosspost_product( $product_id, $product ) {
	
	$target_store_id = 2;

	remove_action( 'woocommerce_update_product', __FUNCTION__, 20, 2 );
	
	switch_to_blog( $target_store_id );
	
	$new_product = new WC_Product_Simple();
	$new_product->set_name( $product->get_name() );
	$new_product->set_regular_price( floatval( $product->get_regular_price() ) );
	$new_product->save();

	restore_current_blog();

}

As you can see, the code is quite simple, but anyway, there are a couple of moments worth keeping in mind.

  • First of all, please note that I’ve hardcoded the blog ID as an argument of the switch_to_blog() function. So, in my WooCommerce multisite network, I am always going to share products with the store with ID=2, but it is up to you how you decide to handle it. Of course, with my plugin, things become easier:
WooCommerce Multisite product sync between multiple stores
Use checkboxes to select specific stores you need to sync a product with.
  • You can also see that I only synced the product name and the product price. To crosspost media files, I recommend you check this tutorial; all the rest (Attributes, Downloads) are described here.
  • One more small thing is that I used the floatval() PHP function before setting the product price. Without this function, the price is not going to be updated.

If you want to include other product data into our PHP function, you can easily do it by using methods of the WC_Product class; for example, let’s include a product slug and description:

$new_product->set_slug( $product->get_slug() );
$new_product->set_description( $product->get_description() );

2. Sync product updates between WooCommerce stores

In the previous chapter, we discussed how you can share WooCommerce products on multiple WooCommerce stores within a WordPress multisite network at the same time, but what if later you decide to update the product, then its copy is going to be created again?

The question is – how to prevent that? Below, in my screenshot, you can get a clear picture of what I am talking about:

How to configure WooCommerce Multisite product sync without creating duplicates
What to do if every time we share a product with a target store, a new copy is created?

I think it would be quite a good idea to store a product ID from “Store 2” in the post meta of the same product on “Store 1”. Then, we just have to check the metadata. If it exists, we are going to update the product; if it doesn’t, create a new one! Let’s do it!

add_action( 'woocommerce_update_product', 'rudr_crosspost_product', 20, 2 );

function rudr_crosspost_product( $product_id, $product ) {

	$target_store_id = 2;

	remove_action( 'woocommerce_update_product', 'rudr_crosspost_product', 20, 2 );

	// let's try to get ID of the same product on Site 2
	$site_2_product_id = $product->get_meta( 'site_2_product_id', true );
	// switch to Site 2
	switch_to_blog( $target_store_id );

	if( $site_2_product_id ) {
		$site_2_product = wc_get_product( $site_2_product_id );
	}

	if( ! $site_2_product ) {
		$site_2_product = new WC_Product_Simple();
	}

	// update the info
	$site_2_product->set_name( $product->get_name() );
	$site_2_product->set_regular_price( floatval( $product->get_regular_price() ) );
	$site_2_product->save();

	restore_current_blog();

	$product->add_meta_data( 'site_2_product_id', $site_2_product->get_id(), true );
	$product->save_meta_data();

}

3. Is it better to connect products using SKU or a meta field?

In the example above, we used meta fields to connect synced products between stores. But the metadata itself isn’t a very persistent thing; for example, if you decide to duplicate a product, then what? Two products in “Store 1” will be connected to the same product in “Store 2”, which is, of course, not good!

That’s why, in real projects, I recommend using the SKU connection for products or at least a custom database table.

Using a custom database table is also a decent idea, because if you’re going to use any duplication plugin for products, none of them will know about the entries in your custom database table; as a result, these entries won’t be duplicated along with products.

Conclusion

I created this chapter to show you that WooCommerce multisite product sync can be easily implemented in the code, and the code is not that difficult, but the main difficulty here is that you need to keep in mind so many things:

  • Different product types (Simple, External, Grouped, Variable, Virtual, Downloadable).
  • Product featured images and gallery images – we need to copy them to sub-stores because WooCommerce doesn’t allow us to use originals here.
  • The possibility to extend products and variations with other plugins; for example, someone would definitely try to add custom fields with ACF.

And so on. As you can see, a lot has been done with my multisite crossposting plugin; if you’re interested in how specific functionality is coded in it, just ask me 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