我刚刚测试了这个,它会起作用的。将其放入您的函数中。php,并且每当未登录的用户尝试访问WooCommerce模板,如商店、产品页面、购物车或结帐时,都会将其重定向到WordPress登录页面。
add_action( \'template_redirect\', \'redirect_users_not_logged_in\' );
/**
* Redirect non logged-in users to login page when they try to access any
* woocommerce template including the cart or checkout page.
*
* @author Joe Dooley - Developing Designs
* @return void
*
*/
function redirect_users_not_logged_in() {
if ( ! is_user_logged_in() && ( is_woocommerce() || is_cart() || is_checkout() ) ) {
auth_redirect();
exit;
}
}