你能帮我解决下面的代码吗?我需要隐藏特定类别的价格,但在商店和类别页面上,而不是在产品详细信息或管理上。
我需要添加is_product_category()和is_shop()编码,但不知道具体在哪里。
add_filter( 'woocommerce_get_price_html', function( $price, $product ) {
if ( is_admin() ) return $price;
// Hide for these category slugs / IDs
$hide_for_categories = array( 'singles', 'albums' );
// 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' );Run Code Online (Sandbox Code Playgroud)