-2

I've a site with 1300 customers who've bought about 5k products between them.

Now, I'd like to convert/migrate those Customers to Wordpress users and keep their purchases, so they can login and see what they've bought.

The customers were all set up as Guest accounts, so none of them currently have user/pass or Wordpress role. I'd like to convert them all to the role Customer and allow them login and download invoices etc.

Is there a tool for this?

1 Answers1

0

You can start here:

/**
 * @snippet       Register Guest Users @ WooCommerce Checkout
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_action( 'woocommerce_thankyou', 'bbloomer_register_guests', 9999 );
 
function bbloomer_register_guests( $order_id ) {
   $order = wc_get_order( $order_id );
   $email = $order->get_billing_email();
   if ( ! email_exists( $email ) && ! username_exists( $email ) ) {
      $customer_id = wc_create_new_customer( $email, '', '', array(
         'first_name' => $order->get_billing_first_name(),
         'last_name'  => $order->get_billing_last_name(),
      ));
      if ( is_wp_error( $customer_id ) ) {
         throw new Exception( $customer_id->get_error_message() );
      }
      wc_update_new_customer_past_orders( $customer_id );
      wc_set_customer_auth_cookie( $customer_id );
   } else {
      $user = get_user_by( 'email', $email );
      wc_update_new_customer_past_orders( $user->ID );
      wc_set_customer_auth_cookie( $user->ID );
   }
}

Add this to your functions.php file of your child theme.

Credit / Source

Whispar Design
  • 72
  • 1
  • 12
  • Thanks Whispar, the customers were originally set up as Guest accounts, none of them currently have user/pass. I've updated the question to say this. – David Henry Sep 19 '22 at 17:47
  • @DavidHenry You can give this a run. I don't know that there is an all-in-one solution but this is the closest I could find to answer your immediate question. – Whispar Design Sep 27 '22 at 01:06