Use Email Address as WordPress Username for WooCommerce Customers

Aug 18, 2020 | WooCommerce, Wordpress

It bugs me that users are automatically given a random username when registering for WordPress through WooCommerce – surely their username should just be their email address, right? Why have two separate details?

Well, thankfully it’s easy to automatically set their username to their email address when they place their first order. Just add the following code to the end of your functions.php file.

// SET EMAIL ADDRESS AS USERNAME ON WOOCOMMERCE CHECKOUT
add_filter( 'pre_user_login' , 'joy_username_email' );
function joy_username_email( $username ) {

    if( isset($_POST['billing_email'] ) ) {
        $username = $_POST['billing_email'];
    }
    if( isset($_POST['email'] ) ) {
        $username = $_POST['email'];
    }
    return $username;
}

Did you find this helpful? Do you have any questions? We’d love to hear from you – leave a comment below!

Browse More Hints & Tips

8 Must-Do Things When Launching a New Website

8 Must-Do Things When Launching a New Website

So you're ready to launch your new website? That's awesome! When launching your website, there's a lot of things you MUST do in order to give your website the best chance of success. Some of these things will help your SEO, others will help you manage your website....

Remove ‘Projects’ post type in Divi

Remove ‘Projects’ post type in Divi

Divi is great, but you don't always need all the features. I often find myself not using the "Projects" post type, and prefer to hide it to keep the back end simple for my clients. It's easy to do, just add the following code to the end of your functions.php file: //...

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *