admin管理员组文章数量:1426040
I have created one page on my WordPress that I want to set only woocommerce user can view it. That mean they must logged in first to be able to view it. For unregistered user if they try to access to that page, we will redirect them to my-account page.
I found this similar solution but this only work for woocommerce pages but how to insert to code for wordpress pages. This is the code:
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');
Let say my page is mydomainname/wordpress-pages
How to be able to restrict that pages? looking forward your help.
I have created one page on my WordPress that I want to set only woocommerce user can view it. That mean they must logged in first to be able to view it. For unregistered user if they try to access to that page, we will redirect them to my-account page.
I found this similar solution but this only work for woocommerce pages but how to insert to code for wordpress pages. This is the code:
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');
Let say my page is mydomainname/wordpress-pages
How to be able to restrict that pages? looking forward your help.
Share Improve this question edited Feb 17, 2016 at 4:38 Adam 16.5k1 gold badge45 silver badges62 bronze badges asked Feb 17, 2016 at 4:29 kunatokunato 32 bronze badges1 Answer
Reset to default 0Add your page slug in if condition too.
function wpse_131562_redirect() {
if (! is_user_logged_in()
&& (is_woocommerce() || is_cart() || is_checkout() || is_page('wordpress-pages'))
) {
// 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');
本文标签: Make wordpress pages accessible for Woocommerce logged in users only
版权声明:本文标题:Make wordpress pages accessible for Woocommerce logged in users only 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745412940a2657550.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论