【问题标题】:How to hide specific product categories price from cart icon dropdown如何从购物车图标下拉菜单中隐藏特定产品类别的价格
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

  • 安德鲁,我使用的是凤凰主题,悬停时,它只显示产品价格而不是小计,我只想隐藏悬停的价格
  • @AzeemAmin 试试它可能仍然有效的代码,小计就是他们所说的价格乘以数量。如果没有,那么我需要获取主题的副本。
  • @AzeemAmin 我需要查看您主题的源代码。将其上传到 Dropbox,以便我下载并查看。
猜你喜欢
  • 2023-04-07
  • 2021-08-24
  • 2021-07-22
  • 1970-01-01
  • 2018-09-06
  • 2017-12-10
  • 2014-07-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多