Share users and WooCommerce memberships between two installations

The woocommerce membership plugin uses the post table to store it’s data, however pretty much all queries from the plugin will contain wc_membership in them (they use it in all of the post_types but it may not catch all the meta_query, will need testing, see if any error or missing data happens, find all the meta keys used by the plugin in queries that don’t contain wc_membership and add them to the strpos)

So there is no associated table and clear separation of data that you could use to load it correctly on the subdomain.

However, you could use the query filter to replace the prefix to lookup the correct table, you need to make sure your prefix on the subwebsite is really unique and long enough so that it won’t interfere with the rest of the query (eg: 2VXOJU8Nxo_)

Then on your sub website install you would add this filter

add_filter('query', function($query) {
  global $wpdb;

  if (strpos($query, 'wc_membership') !== false) {
     $query = str_replace($wpdb->prefix, 'main_website_prefix', $query);
  }
  return $query;
});

Disclaimer: this is not a very safe solution, but pretty much the only possible one with the configuration you are proposing

Another safer solution, would be that instead of having another wordpress instance for the subdomain, you use the same instance

And make or find a plugin to be able to categorize your content and display the correct content on the correct website

Like a multisite install (the memberships plugin doesn’t support multisite)

You could also ask the creator of the plugin if he would be willing to add multisite support for his plugin, so that multisite installs can share the same memberships, that would solve your problem

Leave a Comment