$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Redirect specific link for logged in users only to specific URL|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Redirect specific link for logged in users only to specific URL

matteradmin7PV0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 2

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' );
Post a comment

comment list (0)

  1. No comments so far