Based on Custom product price suffix for selected product categories in WooCommerce answer code, I have used the following to change the price suffix in a specific product category to ‘per kg’. However, there are two products in this category I need to exclude from this. Could anyone tell me whether this is possible please.
add_filter( 'woocommerce_get_price_html', 'conditional_price_suffix', 20, 2 );
function conditional_price_suffix( $price, $product ) {
// HERE define your product categories (can be IDs, slugs or names)
$product_categories = array('cheese');
if( has_term( $product_categories, 'product_cat', $product->get_id() ) )
$price .= ' ' . __('per kg');
return $price;
}
Many thanks