如何从购物车图标下拉菜单中隐藏特定产品类别价格

时间:2018-03-28 10:51:21

标签: php wordpress woocommerce cart

我有一些产品类别,我不会向用户显示价格。成功隐藏产品页面和购物车页面的价格,但当用户将鼠标悬停在图标上时,价格仍会显示在购物车图标中,并显示购物车中产品的下拉列表。

任何人都知道如何解决这个问题?任何帮助将不胜感激。这是我用来隐藏特定类别价格的代码。

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; 
}

1 个答案:

答案 0 :(得分:0)

这应隐藏购物车悬停中的小计,但这取决于您使用的主题。

add_filter('woocommerce_cart_product_subtotal', 'hide_woocommerce_cart_product_subtotal', 10, 4);

function hide_woocommerce_cart_product_subtotal( $sub_total, $product, $quantity, $cart ) {
    $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 $sub_total;
}