Plugin Name: WooCommerce
plugins\woocommerce\templates\global\form-login.php
<label for="username"><?php _e( 'Email', 'woocommerce' ); ?> <span class="required">*</span></label>
It display email instead of username or email which i wanted
includes\class-wc-form-handler.php
if ( empty( $username ) ) {
throw new Exception( '<strong>' . __( 'Error:', 'woocommerce' ) . '</strong> ' . __( 'Email is required.', 'woocommerce' ) );
}
It display validation for email correct but it login with username also
I want it to login only with email and password before checkout
If you look closely at
wp-content/plugins/woocommerce/includes/class-wc-form-handler.phpat line num 878 there is a filterwoocommerce_process_login_errors, which accepts validations error, username and password. So you can overwrite this by this filter help.
Here is the code:
// define the woocommerce_process_login_errors callback
function filter_woocommerce_process_login_errors($validation_error, $post_username, $post_password)
{
//if (strpos($post_username, '@') == FALSE)
if (!filter_var($post_username, FILTER_VALIDATE_EMAIL)) //<--recommend option
{
throw new Exception( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . __( 'Please Enter a Valid Email ID.', 'woocommerce' ) );
}
return $validation_error;
}
// add the filter
add_filter('woocommerce_process_login_errors', 'filter_woocommerce_process_login_errors', 10, 3);
Code goes in functions.php file of your active child theme (or theme). Or also in any plugin php files.
Code is tested and works. in WooCommerce 2.6.X
Hope this helps!
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