admin管理员组文章数量:1130349
i have a custom Woocommerce link that adds a product to the cart and redirects user to the account page:
account/?add-to-cart=15169
I'd like this link to redirect only logged-in users to some specific URL and all the other users to the Account page
Right now:
Not Logged in users redirect to create an account page, that is fine.
Logged in users redirect to Account page
Question: Is there a way to redirect only logged-in users to a specific url for this specific link rather than the account page?
I have tried:
//redirect logged-in users from Account page id=90 to specific page id=15498
function my_logged_in_redirect() {
if ( is_user_logged_in() && is_page( 90 ) )
{
wp_redirect( get_permalink( 15498 ) );
die;
}
}
add_action( 'template_redirect', 'my_logged_in_redirect' );
that works but then the account page is actually not accessible from logged-in users.
i have a custom Woocommerce link that adds a product to the cart and redirects user to the account page:
account/?add-to-cart=15169
I'd like this link to redirect only logged-in users to some specific URL and all the other users to the Account page
Right now:
Not Logged in users redirect to create an account page, that is fine.
Logged in users redirect to Account page
Question: Is there a way to redirect only logged-in users to a specific url for this specific link rather than the account page?
I have tried:
//redirect logged-in users from Account page id=90 to specific page id=15498
function my_logged_in_redirect() {
if ( is_user_logged_in() && is_page( 90 ) )
{
wp_redirect( get_permalink( 15498 ) );
die;
}
}
add_action( 'template_redirect', 'my_logged_in_redirect' );
that works but then the account page is actually not accessible from logged-in users.
Share Improve this question edited Nov 27, 2018 at 22:14 xbass540 asked Nov 27, 2018 at 22:09 xbass540xbass540 1336 bronze badges1 Answer
Reset to default 2you can check the query string and redirect if query string matches the product id.
function my_logged_in_redirect() {
if ( is_user_logged_in() && is_page( 90 ) && $_GET['add-to-cart'] == 15169 ) {
wp_redirect( get_permalink( 15498 ) );
die;
}
}
add_action( 'template_redirect', 'my_logged_in_redirect' );
i have a custom Woocommerce link that adds a product to the cart and redirects user to the account page:
account/?add-to-cart=15169
I'd like this link to redirect only logged-in users to some specific URL and all the other users to the Account page
Right now:
Not Logged in users redirect to create an account page, that is fine.
Logged in users redirect to Account page
Question: Is there a way to redirect only logged-in users to a specific url for this specific link rather than the account page?
I have tried:
//redirect logged-in users from Account page id=90 to specific page id=15498
function my_logged_in_redirect() {
if ( is_user_logged_in() && is_page( 90 ) )
{
wp_redirect( get_permalink( 15498 ) );
die;
}
}
add_action( 'template_redirect', 'my_logged_in_redirect' );
that works but then the account page is actually not accessible from logged-in users.
i have a custom Woocommerce link that adds a product to the cart and redirects user to the account page:
account/?add-to-cart=15169
I'd like this link to redirect only logged-in users to some specific URL and all the other users to the Account page
Right now:
Not Logged in users redirect to create an account page, that is fine.
Logged in users redirect to Account page
Question: Is there a way to redirect only logged-in users to a specific url for this specific link rather than the account page?
I have tried:
//redirect logged-in users from Account page id=90 to specific page id=15498
function my_logged_in_redirect() {
if ( is_user_logged_in() && is_page( 90 ) )
{
wp_redirect( get_permalink( 15498 ) );
die;
}
}
add_action( 'template_redirect', 'my_logged_in_redirect' );
that works but then the account page is actually not accessible from logged-in users.
Share Improve this question edited Nov 27, 2018 at 22:14 xbass540 asked Nov 27, 2018 at 22:09 xbass540xbass540 1336 bronze badges1 Answer
Reset to default 2you can check the query string and redirect if query string matches the product id.
function my_logged_in_redirect() {
if ( is_user_logged_in() && is_page( 90 ) && $_GET['add-to-cart'] == 15169 ) {
wp_redirect( get_permalink( 15498 ) );
die;
}
}
add_action( 'template_redirect', 'my_logged_in_redirect' );
本文标签: Redirect specific link for logged in users only to specific URL
版权声明:本文标题:Redirect specific link for logged in users only to specific URL 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749147320a2323214.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论