add_filter( 'woocommerce_variable_price_html', 'bbloomer_variation_price_format_min', 9999, 2 );
function bbloomer_variation_price_format_min( $price, $product ) {
$prices = $product->get_variation_prices( true );
$min_price = current( $prices['price'] );
$price = sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $min_price ) );
return $price;
}
/**
* @snippet Variable Product Price Range: "From: <del>$$$min_reg_price</del> $$$min_sale_price"
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=275
* @author Rodolfo Melogli
* @compatible WooCommerce 3.5.4
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
add_filter( 'woocommerce_variable_price_html', 'bbloomer_variation_price_format', 10, 2 );
function bbloomer_variation_price_format( $price, $product ) {
// 1. Get min/max regular and sale variation prices
$min_var_reg_price = $product->get_variation_regular_price( 'min', true );
$min_var_sale_price = $product->get_variation_sale_price( 'min', true );
$max_var_reg_price = $product->get_variation_regular_price( 'max', true );
$max_var_sale_price = $product->get_variation_sale_price( 'max', true );
// 2. New $price, unless all variations have exact same prices
if ( $max_var_sale_price ) {
$price = sprintf( __( 'Price: %1$s', 'woocommerce' ), wc_price( $max_var_sale_price ) );
} else {
$price = sprintf( __( 'Price: %1$s', 'woocommerce' ), wc_price( $max_var_reg_price ) );
}
}
// 3. Return $price
return $price;
}