• 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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Are the sites completely separate, or are they on the same network? Or can they be on the same network?

    In that case, I’m the author of a plugin that will easily allow product, stock and order sharing between several blogs.

    Thread Starter michaelnewsomejr

    (@michaelnewsomejr)

    Currently, they on my localhost for testing. I’m not sure where the live sites will be hosted. What is the plugin?

    He, needs a better integration with the shopping carts.
    I am wondering if would be possible have custom code on Site A which would expect a session variable that could be supplied by Site B.
    So users on Site B have a session id and that id is send via API to Site A which uses it to manage the shopping cart.
    … another option might be to start a session on siteA via iframe.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Syncing products between 2 sites when a product is created/updated’ is closed to new replies.