我已经在WordPress上创建了一个页面,我想设置只有woocommerce用户才能查看它。这意味着他们必须先登录才能查看它。对于未注册的用户,如果他们试图访问该页面,我们会将他们重定向到我的帐户页面。
我找到了类似的解决方案,但这只适用于woocommerce页面,但如何插入wordpress页面的代码。代码如下:
function wpse_131562_redirect() {
if (
! is_user_logged_in()
&& (is_woocommerce() || is_cart() || is_checkout())
) {
// feel free to customize the following line to suit your needs
wp_redirect(site_url(\'my-account/\'));
exit;
}
}
add_action(\'template_redirect\', \'wpse_131562_redirect\');
假设我的页面是
mydomainname.com/wordpress-pages如何限制该页面?期待您的帮助。