admin管理员组文章数量:1410737
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
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
Share Improve this question asked Mar 18, 2021 at 21:00 sebseb 11 bronze badge2 Answers
Reset to default 3Try 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);
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();
}
本文标签: WooCommerceprevent login after registration and redirect to custom URL
版权声明:本文标题:Woocommerce, prevent login after registration and redirect to custom URL 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736263576a1922019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论