admin管理员组文章数量:1287963
I am trying to change the WooCommerce Registration button redirect link. This is the code I use for the redirect (which works just fine):
function custom_registration_redirect() {
if(is_user_logged_in()) {
return home_url('/checkout/');
}
}
add_action('woocommerce_registration_redirect', 'custom_registration_redirect', 2);
The issue is: I need to change the redirect based on the page the user is actually on, so I tried doing this:
add_action('wp', 'page_check');
function page_check() {
if (is_page(29179)) {
function custom_registration_redirect() {
if(is_user_logged_in()) {
return home_url('/checkout/');
}
}
add_action('woocommerce_registration_redirect', 'custom_registration_redirect', 2);
}
but for some reason it doesn't work... I know I'm probably missing something here but I don't know what...
Thanks in advance for your help! :-)
I am trying to change the WooCommerce Registration button redirect link. This is the code I use for the redirect (which works just fine):
function custom_registration_redirect() {
if(is_user_logged_in()) {
return home_url('/checkout/');
}
}
add_action('woocommerce_registration_redirect', 'custom_registration_redirect', 2);
The issue is: I need to change the redirect based on the page the user is actually on, so I tried doing this:
add_action('wp', 'page_check');
function page_check() {
if (is_page(29179)) {
function custom_registration_redirect() {
if(is_user_logged_in()) {
return home_url('/checkout/');
}
}
add_action('woocommerce_registration_redirect', 'custom_registration_redirect', 2);
}
but for some reason it doesn't work... I know I'm probably missing something here but I don't know what...
Thanks in advance for your help! :-)
Share Improve this question asked Jan 19, 2020 at 12:47 Sylvain RoulinSylvain Roulin 1 3- Please it's not clear: where is the register form placed ? in a widget? because otherwise you should exactly know the page you're in..normally the registration form is already in checkout page.. – Andrea Somovigo Commented Jan 20, 2020 at 13:30
- Thanks for the reply! It is placed on a page that I created and then I separated the Registration form from the Login form, by following this tutorial: businessbloomer/woocommerce-separate-login-registration. So basically what I have now is a shortcode specifically for the Registration part. – Sylvain Roulin Commented Jan 20, 2020 at 20:03
- did you see my answer? does it work for you? – Andrea Somovigo Commented Jan 22, 2020 at 10:17
1 Answer
Reset to default 1The woocommerce_registration_redirect
is a filter hook, but NOT an action hook.
I've tried the shortcode provided in the mentioned link in your comment above and it works for me in this way:
function AS_redirection_after_registration($redirection_url) {
if($redirection_url =="first-page-slug") // $redirection_url is the slug of the current page where the shortcode is placed
return home_url('/my-page');
elseif($redirection_url=="second-page-slug")
return home_url('/my-second-page');
return home_url('/checkout/');
}
add_filter( 'woocommerce_registration_redirect', 'AS_redirection_after_registration', 10, 1 );
So the $redirection_url
parameter passed to the filter gives you the current page slug where the shortcode is placed and, basing on that, you can decide where to redirect to after registration.
Remember to always return something when using filter hooks,
本文标签: WooCommerce Registration redirect based on page ID
版权声明:本文标题:WooCommerce Registration redirect based on page ID 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741331362a2372783.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论