How can I remove the username field in the registration form in woocommerce?
I tried to remove some line from the woocommerce/myaccount/login-form.php
<?php if ('no' === get_option( 'woocommerce_registration_generate_username' ) ) : ?>
<p class="form-row form-row-wide">
<input type="text" class="customer_login_input" name="username" id="reg_username" placeholder="User name" value="<?php if ( ! empty( $_POST['username'] ) ) echo esc_attr( $_POST['username'] ); ?>" />
</p>
<?php endif; ?>
After that the field doesnt appear in the page, but when I enter the e-mail and the password to register some new account I get the following error: Error: Please enter a valid account ID.
I guess, delete this line brok somethings in the registration form..
Any help would be appreciated
Navigate to WooCommerce -> Settings -> Accounts
tab, scroll down to "Account Creation" section and tick the checkbox for "Automatically generate username from customer email", save your settings.
You've already removed the username field from your registration form, now things should work as expected. Upon registration WooCommerce will derive the username from the email field by splitting it on @ symbol.
So if someone registers with [email protected] , the username will be john . If an existing user with the same username is found, username will be changed to john1.
EDIT (thank you @helgatheviking)
As Kathy has pointed out, you can also use the following plugin
P.S: if you are using an older version of the plugin then the option to automatically generate username from email may not be available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With