I have written custom woocommerce login form on my website. And using Woocommerce User Email Verification plugin for user verification. The issue i facing when user not verifying the email and he tried to login via custom login page the error message not showing. All other error message is showing on login page. Following code are using on my website.
add_shortcode( 'wc_login_form_bbloomer', 'bbloomer_separate_login_form' );
function bbloomer_separate_login_form() {
if ( is_admin() ) return;
ob_start();
if ( ! is_user_logged_in() ) {
// NOTE: THE FOLLOWING
// IF WOOCOMMERCE RELEASES AN UPDATE TO THAT TEMPLATE, YOU MUST CHANGE THIS ACCORDINGLY
if(isset($_POST['login'])) {
$uemail = $_POST['username'];
$password = $_POST['password'];
//$userdata = get_user_by('login', $uemail);
$user = get_user_by('login', $uemail);
//check for email verification success. Here we are manually checking for the field which is set by the WooCommerce User Email Verification plugin.
//$verified_status = get_user_meta( (int) $userdata, 'wcemailverified', true );
$verified_status = get_user_meta( $user->ID, 'wcemailverified', 'true' );
$verified_statusnew = get_user_meta( $user->ID, 'wcemailverifiedcode', 'true' );
if(empty( $uemail ) || empty( $password )){
$error = 'Enter both username and password';
}else if(empty($user)){
// User id check failed
$error = 'There was a problem with your username or password. Please try again.';
}else if(! wp_check_password($password, $user->user_pass, $user->ID)){
// Password check failed
$error = 'There was a problem with your username or password. Please try again.';
}else if (!empty($verified_statusnew) ) {
//User is not an admin and has not validated their email address yet
$error = 'Your account needs to be verified. Please check your email and click the verification link we sent you.';
}else {
$success = 'Successfully logged in';
}
}
?>
<div id="message">
<?php
if(! empty($error) ){
echo '<p class="x-alert x-alert-danger x-alert-block error">'.$error.''.$verified_status.''.$user->roles[0].'';
//print_r($userdata);
}
?>
<?php
if(! empty($success) ){
echo '<p class="x-alert x-alert-success x-alert-block success">'.$success.'';
}
?>
</div>
<form class="woocommerce-form woocommerce-form-login login" method="post">
<?php do_action( 'woocommerce_login_form_start' ); ?>
<label for="username"><?php esc_html_e( 'Username or email address', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="username" autocomplete="username" value="<?php echo ( ! empty( $_POST['username'] ) ) ? esc_attr( wp_unslash( $_POST['username'] ) ) : ''; ?>" /><?php // @codingStandardsIgnoreLine ?>
<label for="password"><?php esc_html_e( 'Password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input class="woocommerce-Input woocommerce-Input--text input-text" type="password" name="password" id="password" autocomplete="current-password" />
<?php do_action( 'woocommerce_login_form' ); ?>
<?php wp_nonce_field( 'woocommerce-login', 'woocommerce-login-nonce' ); ?>
<div class="cust-wholesalebtns">
<div class="cust-loginbtn">
<button type="submit" class="woocommerce-Button button" name="login" value="<?php esc_attr_e( 'Log in', 'woocommerce' ); ?>"><?php esc_html_e( 'Log in', 'woocommerce' ); ?></button>
</div>
<div class="cust-regstrbtn">
<a class="woocommerce-Button button" href="/wholeseller-registration">New User Registration</a>
</div>
</div>
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox inline">
<input class="woocommerce-form__input woocommerce-form__input-checkbox" name="rememberme" type="checkbox" id="rememberme" value="forever" /> <span><?php esc_html_e( 'Remember me', 'woocommerce' ); ?></span>
</label>
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php esc_html_e( 'Lost your password?', 'woocommerce' ); ?></a>
<?php do_action( 'woocommerce_login_form_end' ); ?>
</form>
<?php
// END OF COPIED HTML
// ------------------
}else{
wp_redirect( home_url() );
die();
}
return ob_get_clean();
}
The error message is showing if i changed the below condition at top.
else if (!empty($verified_statusnew) ) {
//User is not an admin and has not validated their email address yet
$error = 'Your account needs to be verified. Please check your email and click the verification link we sent you.';
}