Make wordpress pages accessible for Woocommerce logged in users only

I have created one page on my WordPress that I want to set only woocommerce user can view it. That mean they must logged

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Add 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');

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

相关推荐

  • Make wordpress pages accessible for Woocommerce logged in users only

    I have created one page on my WordPress that I want to set only woocommerce user can view it. That mean they must logged

    4小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信