Multisite Products Sync for WooCommerce
Let’s assume that you have a WordPress multisite network installed and some (or all) of the sites of the network are WooCommerce stores.
The thing is that sometimes you may need to sync WooCommerce products between the sites of your multisite network.
Because we are talking about WordPress Multisite we are not going to work with REST API, the tutorial will be all around switch_to_blog()
function and CRUD layers.
If you do not want to code, you can always use my Simple Multisite Crossposting that allows to sync products between WooCommerce stores.
Creating Products
Let’s assume that we have Store 1 and Store 2 as a part of WordPress multisite network and when a product is created on Store 1, it should be automatically created on Store 2 as well.
We all know save_post
(and save_post_product
) action hooks, but should we use them here? Perhaps we can look towards woocommerce_update_product
appeared in WooCommerce v3 because at least you will have WC_Product object available as its second argument. There is also woocommerce_new_product
hook but it is not going to be activated when you create a WooCommerce product via admin. So let’s stick to woocommerce_update_product
for now.
Also my tutorial about creating products programmatically might by 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 ) {
remove_action( 'woocommerce_update_product', 'rudr_crosspost_product', 20, 2 );
switch_to_blog( 2 );
$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 moments worth to keep in mind.
- First of all please note, that I’ve hardcoded the blog ID on line
7
. So I am always going to crosspost to blog with ID = 2, but it is up to you how you will decide to handle it. Of course, with Simple Multisite Crossposting the things become easier:

- Please take a look at
remove_action()
function on line 7. It is not required here, so I commented it. If you decide to usesave_post
orsave_post_product
action hook, removing this action inside the function will be necessary in terms to avoiding a fatal error “maximum nesting level is reached”. But when usingwoocommerce_update_product
hook removing it inside the function can be omitted, though the hook is going to be activated two times at every product creation/update. - And you can also see that I only synced the product name and the product price. In order to crosspost media files, I recommend you to check this tutorial, all the rest (Attributes, Downloads) is described in this tutorial or in the official WooCommerce documentation.
- One more small thing is that I used
floatval()
function before setting the product price. Without this function the price is not going to be updated.
Updating Products
In the previous chapter I showed you how you can create 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, its copy is going to be created again! And again. The question is how to prevent that?

I think it is quite a good idea to store a product ID from Site 2 in post meta of the same product on Site 1. And then we just have to check that 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 ) {
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( 2 );
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();
}

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 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
Thanks Misha