Multiple WP install with same users database

I am creating a e-commerce website. I am using woocommerce with some cool extensions I bought. I need to make 2 websites, but store the users database (purchases, subscription purchases, etc) as well as products in a single database. The rest of the content should be different (pages, posts etc) so the administrator can see purchases from site1 and site2 while logging in to the one site. Is this possible? Sorry for my bad english.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can do the sharing of users fairly easily.

Basically, both sites would use the same database (set up in wp-config.php), but each would get it’s own, unique $table_prefix.

From there, you can specify custom user and user meta tables that are the same for each site.

<?php
// site 1 wp-config.php
$table_prefix = 'site1_';
define('CUSTOM_USER_TABLE', 'custom_users');
define('CUSTOM_USER_META_TABLE', 'custom_usermeta');

For site two…

<?php
// site 2 wp-config.php
$table_prefix = 'site2_';
define('CUSTOM_USER_TABLE', 'custom_users');
define('CUSTOM_USER_META_TABLE', 'custom_usermeta');

this will effectively isolate the content of each site, but allow them to share the same userbase. It also means editing a user one one site would change that user on the other site, of course.

WooCommerce uses custom post types as containers for their orders, subscriptions, etc. so you’re not going to be able to “share” them between two sites easily at the application level. You could use something like MySQL triggers to auto update from one sites orders to the other, but that seems really brittle.

Method 2

I have done this in both site.

define('CUSTOM_USER_TABLE', 'custom_users');
define('CUSTOM_USER_META_TABLE', 'custom_usermeta');

I have imported 3000+ user from first site to second. (Second site is new)
When I try to login second site.It logged in but can not find user role and and so can not enter admin panel. So I have manually correct user role in second site. Now it is running fine.
However new users have no problem.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x