Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set full email address as username when registering through WooCommerce

WooCommerce under Settings/Account has an option named

Automatically generate username from customer email

but the username it generates is not the full email address.

[email protected]

becomes myemail as a username.

What method would I need to hook into to override the user generation so that the full email is set as the username?

like image 415
Patrick Klug Avatar asked Sep 05 '16 23:09

Patrick Klug


1 Answers

You can use something like this in your functions.php. The woocommerce_new_customer_username filter could be used to change the generated username. If you just return the customer email as the username, it will be used instead of the generated one (in your case the name before @).

function my_new_customer_username( $username, $email, $new_user_args, $suffix ) {
    return $email;
}
add_filter( 'woocommerce_new_customer_username', 'my_new_customer_username', 10, 4 );
like image 66
Martin Šnajdr Avatar answered Nov 14 '22 23:11

Martin Šnajdr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!