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.
you 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' );