woocommerce offtopic - Redirect if current user is logged out and current page is my-account

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 r

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' );
    die();
}

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' );
    die();
}
Share Improve this question asked Jun 27, 2016 at 16:11 Thomas_HoadleyThomas_Hoadley 3071 gold badge6 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 8

Fixed!

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') );
      die();
  }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745103120a4611394.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信