Until recently we had a single members area that also integrated the store and the data was all recorded on a single DB.
Now, since the merchandising products are also coming out, we decided to create a separate store, to keep everything cleaner.
In this store we also sell access to the members area and we would like to do the following: The user who buys on site A (the store) is registered as a new user also on site B (the members area).
This is the code I've used so far, but I don't know how to continue:
//Code that links the DB of the site B
function connect_db_membership(){
global $db_membership;
$db_membership = new wpdb('USERNAME', 'PASSWORD', 'DATABASE_NAME', 'HOSTNAME');
}
add_action('init', 'connect_db_membership');
//Code that retrieves the first name, last name and email of the user who has just completed the purchase and passes it to the DB of site B.
add_action( 'woocommerce_order_status_completed', 'change_role_on_purchase' );
function change_role_on_purchase( $order_id ) {
global $db_membership;
$order = new WC_Order( $order_id );
$items = $order->get_items();
$order = wc_get_order( $order_id );
$order_data = $order->get_data();
$order_billing_first_name = $order_data['billing']['first_name'];
$order_billing_last_name = $order_data['billing']['last_name'];
$order_billing_email = $order_data['billing']['email'];
}
Note: I would like the password to be set directly through the link that arrives by email.
Useful information:
- The two sites are both on WordPress;
- The two sites are all hosted on the same hosting.
- The sites are not on a multisite and I don't want to put them there since the only data they have to share is the user's data.