Patrick Klug Patrick Klug - 1 year ago 117
PHP Question

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.

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?

Answer Source

Simply use the hook pre_user_login

add_filter( 'pre_user_login' , 'wpso_same_user_email' );

function wpso_same_user_email( $user_login ) {

    if( isset($_POST['billing_email'] ) ) {
        $user_login = $_POST['billing_email'];
    if( isset($_POST['email'] ) ) {
        $user_login = $_POST['email'];
    return $user_login;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download