duanlang0025 2019-05-30 07:53
浏览 134

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

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

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.';
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP