【发布时间】:2017-02-10 16:16:21
【问题描述】:
在 WooCommerce 中,我试图根据某些产品类别从我的主页滑块中删除“添加到购物车”按钮并隐藏价格。
我已尝试使用该代码:
/* Code for authorisation */
function show_price_logged($price){
if(! is_user_logged_in()) {
if(has_term( 'teamine', 'product_cat' )){ /* sub categories need not authorisation, but thier parent category needs authorisation */
return $price;
}
if(has_term( 'epicuren', 'product_cat' ) || has_term( 'revision', 'product_cat' ) || has_term( 'image-2', 'product_cat' )){ /* categories needs authorisation */
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
return '<a class="amount authorizelink" href="/how-to-get-authorized-its-easy">Authorization needed to purchase <span>Click Here</span></a>';
}
if(has_term( 'skinceuticals', 'product_cat' ) || has_term( 'lira', 'product_cat' )){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
return '<a href="www.radiantskincarespa.com">Please contact the Spa to arrange a consultation and to purchase this product <span></span></a>';
}
else{
return $price;
}
}
else return $price;
}
但它没有按预期工作,并且在条件匹配时不会删除添加到购物车的按钮。
任何帮助将不胜感激。我怎样才能做到这一点?
谢谢。
更新
【问题讨论】:
-
你在哪里调用或挂钩你的函数
show_price_logged($price)?
标签: php wordpress woocommerce categories product