将联系页面限制为 WooCommerce 用户?

问题描述 投票:0回答:1

我正在使用 WooCommerce (8.1.1) 和 Divi 主题构建一个电子商务网站。 我找到了如何限制对 WooCommerce 页面的访问以登录用户,但我想将我创建的联系页面限制为 WooCommerce 登录用户。 我想我必须自定义此处找到的functions.php(如何将页面限制为Woocommerce中的用户?)? 欢迎任何帮助,谢谢。

wordpress woocommerce restriction
1个回答
0
投票

尝试以下操作,在下面定义您的联系页面 slug:


add_action('template_redirect', 'contact_page_unlogged_users_redirect');
function contact_page_unlogged_users_redirect() {
    $targeted_page = 'contact'; // <== Set the desired page slug

    if ( ! is_user_logged_in() && is_page( $targeted_page ) ) {
        // feel free to customize the following line to suit your needs
        wp_redirect(home_url());
        exit();
    }
}

代码位于子主题的functions.php 文件中(或插件中)。应该可以。

© www.soinside.com 2019 - 2024. All rights reserved.