在购物车页面上隐藏特定类别的价格
Hide price for specific categories on cart page
我试图从产品页面 + 购物车中隐藏特定类别的价格,并且我正在使用我在其他地方找到的代码片段。
<?php
add_filter( 'woocommerce_get_price_html', function( $price, $product ) {
if ( is_admin() ) return $price;
// Hide for these category slugs / IDs
$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; // Return original price
}, 10, 2 );
add_filter( 'woocommerce_cart_item_price', '__return_false' );
add_filter( 'woocommerce_cart_item_subtotal', '__return_false' );
?>
我面临的问题是此代码隐藏了 cart.It 的所有类别价格,非常适合产品页面,但不是购物车。任何人都可以帮助我更改代码中的内容吗?我是 WordPress 编码的新手。
非常感谢。
这应该可以解决问题,将在您的类别列表中的每个产品的购物车页面上隐藏价格和总计。
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
add_filter( 'woocommerce_get_price_html', function( $price, $product ) {
if ( is_admin() ) return $price;
// Hide for these category slugs / IDs
$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; // Return original price
}, 10, 2 );
add_filter( 'woocommerce_cart_item_price', '__return_false' );
add_filter( 'woocommerce_cart_item_subtotal', '__return_false' );
?>
我面临的问题是此代码隐藏了 cart.It 的所有类别价格,非常适合产品页面,但不是购物车。任何人都可以帮助我更改代码中的内容吗?我是 WordPress 编码的新手。
非常感谢。
这应该可以解决问题,将在您的类别列表中的每个产品的购物车页面上隐藏价格和总计。
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;
}