如何从购物车图标下拉菜单中隐藏特定产品类别的价格 [英] How to hide specific product categories price from cart icon dropdown

查看:65
本文介绍了如何从购物车图标下拉菜单中隐藏特定产品类别的价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些产品类别,不向用户显示价格.成功地从产品页面以及购物车页面中隐藏了价格,但是当用户将鼠标悬停在该图标上时,价格仍显示在购物车图标中,并且显示了购物车中的产品的下拉列表.

I have some product categories which I don't to show the price to the user. Successfully hide the price from the product pages and also from the cart page but the price still showing in the cart icon when the user hovers over the icon and a dropdown list appear of the products that are in the cart.

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

Anyone know how to fix this? Any help will be appreciated.This is the code that I am using to hide the price for the specific category.

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

推荐答案

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

This should hide the subtotal in the cart hover but it's dependent on the theme you are using.

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

这篇关于如何从购物车图标下拉菜单中隐藏特定产品类别的价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆