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

Autoplay Videos in Divi

Autoplay Videos in Divi

Setting videos to autoplay has bugged website developers for years, and in Divi there are no default options to Autoplay your videos. Some people suggest setting your video as a background to allow autoplay, but this comes with its own issues (like setting the...

How to Choose the Best Website Address (Domain/URL)

How to Choose the Best Website Address (Domain/URL)

This article was first written 24 Sept 2011, and has been updated August 2020. What is a website address? Your website address, or domain name, is used to identify and access your website. It looks something like www.yourwebsite.com. No two website addresses...

0 Comments

Submit a Comment

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