Prevent automatic login when registering in woocommerce and redirecting to the login page?

I am developing a website using woo commerce wordpress. I share the login and registration page by link this solution

How can I redirect the registration page to the login page after successful registration without logging in. The user must log in with a username and password.

my login page

www.example.com/my-account/

and registration page

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

+6
source share
2 answers

After a great search, I found a solution for this

Step1: add WP Approve User

Step 2: add this 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); 
+11
source

Below the line of code is the line woocommerce/includes/class-wc-form-handler.php No. 905.

wp_redirect( apply_filters( 'woocommerce_registration_redirect', $redirect ) );

I am correcting the answer given by @ user3518270

The below line will not work as it is a filter used by woocommerce. Therefore, you need to use add_filter () instead of add_action ()

 add_action('woocommerce_registration_redirect', 'user_autologout', 2); /* 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_filter('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); 
+3
source

Source: https://habr.com/ru/post/971267/


All Articles