【发布时间】:2018-09-06 11:41:40
【问题描述】:
我正在尝试从产品页面 + 购物车中隐藏特定类别的价格,并且我正在使用我在其他地方找到的代码 sn-p。
<?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' );
?>
我面临的问题是此代码隐藏了购物车中的所有类别价格。它非常适合产品页面,但不适用于购物车。任何人都可以帮助我在代码中进行哪些更改?我是 WordPress 编码的新手。
非常感谢。
【问题讨论】:
标签: php wordpress woocommerce content-management-system cart