如何在woocommerce自定义登录页面上显示用户已验证的电子邮件错误消息

时间:2019-05-30 07:53:21

标签: php wordpress woocommerce

我已经在我的网站上编写了自定义woocommerce登录表单。并使用Woocommerce User Email Verification插件进行用户验证。当用户不验证电子邮件并且他尝试通过自定义登录页面登录时,我面临的问题是错误消息未显示。所有其他错误消息都显示在登录页面上。我的网站上正在使用以下代码。

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' ); ?>&nbsp;<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' ); ?>&nbsp;<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();
}

如果我在顶部更改了以下条件,则会显示错误消息。

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.';
    }

0 个答案:

没有答案