Prevent automatic login when register in woocommerce and redirect to login page?

前端 未结 4 1358
刺人心
刺人心 2021-01-01 01:41

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 pa

4条回答
  •  独厮守ぢ
    2021-01-01 01:49

    After a lot of search I found the solution for this

    Step1: add WP Approve User

    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 = '

    Send in your registration application today!
    NOTE: Your account will be held for moderation and you will be unable to login until it is approved.

    '; if( isset($_REQUEST['approved']) ){ $approved = $_REQUEST['approved']; if ($approved == 'false') echo '

    Registration successful! You will be notified upon approval of your account.

    '; else echo $not_approved_message; } else echo $not_approved_message; } add_action('woocommerce_before_customer_login_form', 'registration_message', 2);

提交回复
热议问题