Filter to change price display based on category?
-
Hello,
I would like to change the price display to say “per month” but only if it is in one of several categories.
The function and filter to change the price seems easy enough, I just cant figure out how to adapt it so it only applies to products of certain categories
Can anybody help? Please don’t recommend plugins.
function mmi_change_product_price_display( $price ) { $price .= ' per month'; return $price; } add_filter( 'woocommerce_get_price_html', 'mmi_change_product_price_display' ); add_filter( 'woocommerce_cart_item_price', 'mmi_change_product_price_display' );
I tried just wrapping it like this:
function mmi_change_product_price_display( $price ) { if ( is_product() && has_term( 'oboe-rentals', 'product_cat' ) ) { $price .= ' per month'; return $price; } } add_filter( 'woocommerce_get_price_html', 'mmi_change_product_price_display' ); add_filter( 'woocommerce_cart_item_price', 'mmi_change_product_price_display' );
But it didnt work, presumably because my php skills are deficient.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Filter to change price display based on category?’ is closed to new replies.