Try the following code that uses has_term()
conditional function for defined product categories:
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('t-shirts','hoodies');
if( has_term( $product_categories, 'product_cat', $product->get_id() ) )
$price .= ' ' . __('per M/T');
return $price;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
To exclude defined product categories you will replace:
if( has_term( $product_categories, 'product_cat', $product->get_id() ) )
simply by:
if( ! has_term( $product_categories, 'product_cat', $product->get_id() ) )
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…