I have added a code snippet to my WooCommerce installation, which allows you to enter a zero price for a variant, and it will say “Call for Price”. However, I also have a code snippet added, which shows a variants lowest value as a “from” price. So for example, if the product variant prices ranged between £50 and £100, it would say “From: £50”.
However, the problem now comes that when I have a product variant with price 0.. the price displays as “From: £0.00”.
So, for variants only, I would like the code to be able to select the next lowest variant price that is not zero.
To see the example of the problem, you can visit:
https://webdrive.co.uk/repair-services/ipad-pro-genuine-full-screen-repair/
Any help would be greatly appreciated.
The code I am using currently is:
add_filter( 'woocommerce_get_price_html', 'empty_and_zero_price_display', 20, 2 );
function empty_and_zero_price_display( $price, $product ) {
$blank_price = __('Call for Price', 'woocommerce');
$zero_price = __('Call for Price', 'woocommerce');
if( ! $product->is_type('variable') ) {
if ( '' === $product->get_price() ) {
return $blank_price;
} else if (0 == $product->get_price() ) {
return $zero_price;
}
}
return $price;
}
LantrixUK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.