You may want to disable the variable product price range which usually looks like $100-$999. With this snippet you will be able to hide the highest price, plus add a “From: ” in front of the minimum price. All you need is pasting the following code in your child theme’s functions.php 🙂

WooCommerce: Disable Variation Price Range @ Single Product Page
WooCommerce: Disable Variation Price Range @ Single Product Page WooCommerce: Disable Variation Price Range @ Single Product Page

PHP Snippet 1: Change WooCommerce Variable Product Price Range $$$-$$$ to “From: $$$min_price”

This version is also compatible with other plugins that edit product prices (such as Dynamic Pricing). This snippet will print a unique “From:” price, which is the lowest of all prices, including sale prices.


/**
 * @snippet       Variable Product Price Range: "From: $$$min_price"
 * @how-to        Get CustomizeWoo.com FREE
 * @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_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;
}

PHP Snippet 2: Change WooCommerce Variable Product Price Range $$$-$$$ to “From: $$$min_reg_price $$$min_sale_price”

This snippet will print a “From:” price, and if there is a sale price, it will also include the original regular price (slashed).


/**
 * @snippet       Variable Product Price Range: "From: <del>$$$min_reg_price</del> $$$min_sale_price"
 * @how-to        Get CustomizeWoo.com FREE
 * @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 ( ! ( $min_var_reg_price == $max_var_reg_price && $min_var_sale_price == $max_var_sale_price ) ) {	
	if ( $min_var_sale_price < $min_var_reg_price ) {
		$price = sprintf( __( 'From: <del>%1$s</del><ins>%2$s</ins>', 'woocommerce' ), wc_price( $min_var_reg_price ), wc_price( $min_var_sale_price ) );
	} else {
		$price = sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $min_var_reg_price ) );
	}
}

// 3. Return $price

return $price;
}

Share:

Leave a Reply