Use Email Address As Username When Registering a New Account

In the WooCommerce > Settings > Accounts and Privacy, there is the option
” When creating an account, automatically generate an account username for the customer based on their name, surname or email”
When you check it, the system creates a username based on name+surname of the user.
In order to force the use of e-mail address as username add the code below to functions.php

// Force WooCommerce To Use Email Address As Username When Registering a New Account

add_filter( 'pre_user_login' , 'awk_set_username_to_email' );

function awk_set_username_to_email( $user_login ) {

    if( isset($_POST['billing_email'] ) ) {
        $user_login = $_POST['billing_email'];
    }
    if( isset($_POST['email'] ) ) {
        $user_login = $_POST['email'];
    }
    return $user_login;
}
Scroll to Top