禁止在woocommerce中注册并重定向到登录页面时自动登录? [英] Prevent automatic login when register in woocommerce and redirect to login page?

查看:174
本文介绍了禁止在woocommerce中注册并重定向到登录页面时自动登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用woo Commerce wordpress设计一个网站,我通过参考

I am designing a website with woo commerce wordpress I have separate the login and register page by reference to this solution

成功注册后,如何在不登录的情况下将注册页面重定向到登录页面.用户需要使用电子邮件发送的用户名和密码登录.

How can I redirect the registration page to login page after successful registration without logged in. The user need to login there with the emailed username and password.

我的登录页面是

www.example.com/my-account/

www.example.com/my-account/

注册页面是

www.example.com/my-account/?action=register

www.example.com/my-account/?action=register

推荐答案

经过大量搜索,我找到了解决方案

After a lot of search I found the solution for this

第一步:添加 WP批准用户

第二步:将这些代码添加到主题功能文件中

Step2: add these code to ur theme function file

/* Stop auto login */


function user_autologout(){
       if ( is_user_logged_in() ) {
                $current_user = wp_get_current_user();
                $user_id = $current_user->ID;
                $approved_status = get_user_meta($user_id, 'wp-approve-user', true);
                //if the user hasn't been approved yet by WP Approve User plugin, destroy the cookie to kill the session and log them out
        if ( $approved_status == 1 ){
            return $redirect_url;
        }
                else{
            wp_logout();
                        return get_permalink(woocommerce_get_page_id('myaccount')) . "?approved=false";
                }
        }
}
add_action('woocommerce_registration_redirect', 'user_autologout', 2);
function registration_message(){
        $not_approved_message = '<p class="registration">Send in your registration application today!<br /> NOTE: Your account will be held for moderation and you will be unable to login until it is approved.</p>';
        if( isset($_REQUEST['approved']) ){
                $approved = $_REQUEST['approved'];
                if ($approved == 'false')  echo '<p class="registration successful">Registration successful! You will be notified upon approval of your account.</p>';
                else echo $not_approved_message;
        }
        else echo $not_approved_message;
}
add_action('woocommerce_before_customer_login_form', 'registration_message', 2);

这篇关于禁止在woocommerce中注册并重定向到登录页面时自动登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆