0

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.

4

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.

0

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.

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.