I’m looking for a way to prevent the automatic login after registration (i.e. by logging him out after registration) and redirect him to a custom URL.
So far I’m only able to do both of them individually, but the combination of it is not working.
For redirect after registration I’m using the following:
add_filter( 'woocommerce_registration_redirect', 'custom_redirection_after_registration', 10, 1 );
function custom_redirection_after_registration( $redirection_url ){
// Change the redirection Url
$redirection_url = "https://...";
return $redirection_url;
}
When including the wp_logout() function within the function above, I think that the redirect after logout is being triggered. If that assumption is correct, I unfortunately don’t know how I can redirect only that logout that’s being triggered directly after the registration.
I hope that anyone can help me out? It’s greatly appreciated!
Best regards
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Try this, It may helpful.
function wc_custom_registration_redirect() {
wp_logout();
wp_destroy_current_session();
return home_url('/');
}
add_action('woocommerce_registration_redirect', 'wc_custom_registration_redirect', 99);
Method 2
Whoever has also the same question as I had:
This is how I got it to work:
add_filter('woocommerce_registration_redirect', 'custom_redirection_after_registration', 1);
function custom_redirection_after_registration( $redirection_url ){
// Change the redirection Url
add_action('wp_logout','only_redirect_unverfied_users_after_registration',1);
wp_logout();
wp_destroy_current_session();
$redirection_url = "https://...";
return $redirection_url;
}
function only_redirect_unverfied_users_after_registration(){
$redirection_url = "https://";
wp_redirect( $redirection_url);
exit();
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0