如何解决根据用户角色和分类术语隐藏产品页面
我正在尝试根据客户的角色和产品的分类术语将客户重定向回商店页面。
这里的区别是,如果产品没有所选术语,我想重定向。这是因为产品具有多个条款。目前我所拥有的与我所需要的相反,它仅重定向正确的产品。
这些是我要实现的规则:
- 页面 IS 是单个产品页面
- 用户 IS 'logged_in'
- 用户角色 IS 'super_wholesale_customer'
- 产品不包含术语“ 380”
这是我到目前为止所拥有的:
// On single product pages,redirect to shop and display a custom notice for specific products
add_action( 'template_redirect','wcpp_redirect_hiding_product_detail' );
function wcpp_redirect_hiding_product_detail() {
if ( is_product() ) {
if ( ( is_user_logged_in() || ! current_user_can('super_wholesale_customer') )
&& has_term( '380','Role' ) ) {
wc_add_notice(__("Sorry,but you are not allowed yet to see this product."),'notice' );
$redirect_url = get_permalink( get_option('woocommerce_shop_page_id') );
wp_redirect($redirect_url);
exit(); // Always exit
};
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。