Syncing products between 2 sites when a product is created/updated
-
I am created 2 WooCommerce sites for a client. Site A sells wine. Site B sells a large variety of products. They would like to sell the wine from Site A on Site B, as well.
I was able to get the products to display using Rest API, but was not able to add to cart or purchase, only view. So, I thought maybe I would be able to have the wine products actually create on Site B, and have them just sync up with a custom function when something is added/edited on Site A.
I created this function:
function sync_products( $post_id ) { // Install: // composer require automattic/woocommerce // Setup: require __DIR__ . '/vendor/autoload.php'; use Automattic\WooCommerce\Client; $woocommerce = new Client( 'https://localhost/mystore/', // Your store URL 'ck_d0b60946c6250be3f34010ab1f6c2b2c82630f49', // Your consumer key 'cs_21b28aaeda7eb6514a9bef1f13c3ced0d57b7368', // Your consumer secret [ 'version' => 'v3' // WooCommerce API version ] ); } add_action( 'save_post_product', 'sync_products');
However, I get the white screen of death when I attempt to created/edit a product on the dashboard. Any ideas on what I’m doing wrong?
FYI: I put this function in the functions.php file. I have only created the authentication, at the moment. It seems to be this line causing the white screen: use Automattic\WooCommerce\Client;
Thanks in advance.
- The topic ‘Syncing products between 2 sites when a product is created/updated’ is closed to new replies.