dongxi7704 2015-01-14 04:23
浏览 20
已采纳

如何在Woocommerce中将页面限制为用户?

I am working on a site and there I am using woocommerce.

If the user logged in or not, they can add to cart a product, go to cart, go to checkout. But now I want that only logged in users can access these pages.

If the guest user click on the add to cart button the message appear You must be logged in. If user go to cart page or checkout page they redirect to register page.

Is there any plugin or hook in Woocommerce?

  • 写回答

1条回答 默认 最新

  • douwu8524 2015-01-14 04:29
    关注

    Found here: https://wordpress.stackexchange.com/questions/131562/make-woocommerce-pages-accessible-for-logged-in-users-only

    Put this in your functions.php file:

    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(home_url());
            exit;
        }
    }
    add_action('template_redirect', 'wpse_131562_redirect');
    

    What does it do? We check if a not-logged-in user wants to see a WooCommerce page, and redirect him/her to our home page.

    In your case, you can customize the redirect to the You must be logged page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 51单片机最小开发板系统,想让寻迹小车在全检测到黑线(寻迹模块代码在第一块板子上)时蜂鸣器响(在第二块板子上)
  • ¥15 pbootcms多选调用成列表
  • ¥15 51单片机oled显示时钟
  • ¥15 小规模TSP问题的动态规划求解
  • ¥25 kubelet.service: Failed with result 'exit-code'.
  • ¥15 bitvise黑框内一键部署v2ray提示账户没有root怎么解决
  • ¥15 车型识别以及相似度匹配中细节特征提取以及图像模糊问题
  • ¥15 怎么用鸿蒙的ArkTs写出来啊
  • ¥30 websocket服务端多线程通信
  • ¥15 JNA 方法调用.dll异常
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部