I need my woocommerce site to do the following. If the user visits the /my-account page but is logged out I need it to redirect to the /login page. I currently have half of it (if is logged out) but I need to test if it's the my-account/ page as well which I can't figure out. Any help would be really appreciated!

if ( !is_user_logged_in()) {
    wp_redirect( '/login' );


I had to use the wp hook which means that the redirect function is only run once the whole page is loaded! Sweet :)

add_action( 'wp', 'redirect' );
function redirect() {
  if ( is_page('my-account') && !is_user_logged_in() ) {
      wp_redirect( home_url('/login') );

protected by Community Oct 7 at 0:09

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.