Reputation: 69
I would like to use e-mail id as username in my WooCommerce site. I can see both (username & e-mail ID) in my website I would like to show only email id and password on the registration page. Let me know how to do this.
Upvotes: 2
Views: 5007
Reputation: 640
I don't remember where I found it, but I use this on one of my sites. Place it in your theme's functions.php file.
/**
// Allow customers to login with their email address or username
**/
add_filter('authenticate', 'internet_allow_email_login', 20, 3);
/**
* internet_allow_email_login filter to the authenticate filter hook, to fetch a username based on entered email
* @param obj $user
* @param string $username [description]
* @param string $password [description]
* @return boolean
*/
function internet_allow_email_login( $user, $username, $password ) {
if ( is_email( $username ) ) {
$user = get_user_by_email( $username );
if ( $user ) $username = $user->user_login;
}
return wp_authenticate_username_password( null, $username, $password );
}
?>
Upvotes: 1