Add product to basket from different multisite blog using woocommerce

Question

I have a multisite on different domains.

site-one.com

site-two.com

I am currently using Woocommerce Multistore plugin (https://woomultistore.com/) to sync products from one site to another as they are to be exactly the same. To be honest the plugin has many faults and bugs and I want to try something custom.

My thoughts were that instead of copying the products from one site to another that I could use a hook like pre_get_posts to get the products of site-one and display them on site-two.

I have had initial success in this by this simple function that gets products from the DB associated with site-on if its a product post type:

add_filter( 'pre_get_posts', 'get_post_from_site_one' );
function get_post_from_site_one($query) {
    if ( in_array ( $query->get('post_type'), array('product') ) )  {
        global $wpdb;
        $wpdb->posts = 'wp_posts';
        $wpdb->postmeta = 'wp_postmeta';
        return $query;
    }
}

This has its limitations as it only works frontend for now but the other hurdle I am looking to fix is that on site-two the products are showing but I cant add them to the basket. Nothing happens when I try – page just reloads.

The add to cart ajax returns this error in console:

{"error":true,"product_url":false}

Firstly I would like to know whether this route I’m taking will eventually work or is it impossible and based on that – if it is possible where should I go from here? Im stumped as to how to add to basket?!

0
MikeeeGeee 2 months 0 Answers 11 views 0

Leave an answer