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
1 Answer
Reset to default 8Fixed!
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条)