【发布时间】:2021-09-08 16:55:27
【问题描述】:
我有一些产品类别不向用户显示价格。成功从产品页面和购物车页面隐藏价格,但当用户将鼠标悬停在购物车图标上时价格仍显示在购物车图标上,并且出现购物车中产品的下拉列表。
有人知道如何解决这个问题吗?任何帮助将不胜感激。这是我用来隐藏特定类别价格的代码。
add_filter('woocommerce_cart_item_price', 'hide_woocommerce_cart_item_price', 10, 3);
add_filter('woocommerce_cart_item_subtotal', 'hide_woocommerce_cart_item_price', 10, 3);
function hide_woocommerce_cart_item_price( $price, $cart_item, $cart_item_key ) {
$product = wc_get_product($cart_item['product_id']);
$hide_for_categories = array( 'berkley','cotton-lite','kinna','linen','luster','nairobi','panama','plisse','prints','sequoia','shantung','brocade','boucle','dover','lite-out','lite-out-duplex','moire','sheerweave-blackout','sutton','texas-green','windsor','sheer','sheerweave-3-5-10','sheerweave-specialty');
// Don't show price when its in one of the categories
if ( has_term( $hide_for_categories, 'product_cat', $product->get_id() ) ) {
return '';
}
return $price;
}
【问题讨论】:
-
你用的是什么主题?
标签: php wordpress woocommerce cart