I'm trying to create a custom registration for the customer in the woocommerce registration page. Basically, I want the users to register with their their basic details, without their password. Once they do, I will be the one to generate their password for them in the wordpress dashboard. Is this possible? And how can I do this?
1 Answer
Use this snippet to create user without password
$website = "http://example.com";
$userdata = array(
'user_login' => 'login_name',
'user_url' => $website,
'user_pass' => NULL // When creating an user, password is expected.
);
$user_id = wp_insert_user( $userdata ) ;
//after this you can update user on this way
update_user_meta( $user_id, 'some_meta_key', $meta_value );
or
//create user with random password
$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
$user_id = wp_create_user( $user_name, $random_password, $user_email );
//then update/add user information on this way
update_user_meta( $user_id, 'some_meta_key', $meta_value );
-
Hello, thank you for your answer. I was about to do this, but I found it easier to use the auto generate password option from woocommerce settings and modify the email that the customer got automatically by removing the option to send their password. Again, thank you.– kitminJul 10, 2019 at 5:33
user_pass
$userdata = array( 'user_login' => XXX, 'user_url' => XXX, 'user_pass' => STATIC_PWD );
$user_id = wp_insert_user( $userdata ) ;