Reputation: 67
I have products with prices that need to all end with "per sq. ft." I want this to only apply to products of a particular category and only when the price is greater than 0.
When the product has no price listed I need the price to say "Call for Price" without the square footage text after it.
So here is a start I found online but they dont have any conditions associated with them so they apply to all product all the time.
/* Display "Call for Price" instead of empty price */
add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
$vat = ' per sq. ft.';
return $price . $vat;
}
/* Display "Call for Price" instead of empty price */
add_filter('woocommerce_empty_price_html', 'custom_call_for_price');
add_filter('woocommerce_variable_empty_price_html', 'custom_call_for_price');
add_filter('woocommerce_variation_empty_price_html', 'custom_call_for_price');
function custom_call_for_price() {
return 'Call for Price';
}
Upvotes: 2
Views: 3411
Reputation: 67
Thank you both for the help. I used both of your code strings and here is what i came up with:
add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message($price) {
if ( !has_term( 'stone', 'product_cat' ) ) {
return $price;
} elseif (!empty($price)){
$vat = ' per ft<sup>2</sup>';
return $price . $vat;
}else{
return 'Call for Price';
}
}
Upvotes: 0
Reputation: 748
add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message($price) {
if(!empty($price)){
$vat = 'Your Text Here';
return $price . $vat;
}else{
return 'CALL FOR PRICE';
}
}
I hope this works.
Upvotes: 1