I have a membership site (let's call it mainsite.com) using woocommerce memberships to protect certain pages.

I wish to create a second wordpress site (sub.mainsite.com) which uses the same wp user tables as the main site so signing up/logging into mainsite.com also registers/logs them into sub.mainsite.com.

This is fairly straight forward as per this article as both are on the same server https://trickspanda.com/wordpress-share-users-login/

However, I want the second site to also have woocommerce membership to protect certain pages.

Is it possible / how can I set up the second site so that this site's install of the membership plugin reads the main site's wc_membership tables (and does not create their own tables) therefore allowing memberships to be synced across both sites?


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

  • Thank you so much Toffee! Really appreciate your time! Enjoy your bounty! – sw123456 Mar 12 '20 at 7:02
  • That's a really clever approach Toffee. Kudos. – Tony Djukic Mar 13 '20 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.