Home » WooCommerce: Disable Variable Product Price Range $$$-$$$

WooCommerce: Disable Variable Product Price Range $$$-$$$

by Tutor Aspire

You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case).

With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price – variable products with a single price (i.e. all variations have the same price) will keep their original format.

Simply paste the following code in your child theme’s functions.php and enjoy!

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

PHP Snippet: Change WooCommerce Variable Product Price Range Format to “From: min_price”

This version is also compatible with other plugins that edit product prices (such as Dynamic Pricing). This snippet will display a single price, which is the lowest of all prices, including sale prices.

This snippet won’t change the format of variable products with a single price (when all variations have the same regular price).

/**
 * @snippet       Variable Product Price Range: "From: min_price"
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'woocommerce_variable_price_html', 'tutoraspire_variation_price_format_min', 9999, 2 );

function tutoraspire_variation_price_format_min( $price, $product ) {
   $prices = $product->get_variation_prices( true );
   $min_price = current( $prices['price'] );
   $max_price = end( $prices['price'] );
   $min_reg_price = current( $prices['regular_price'] );
$max_reg_price = end( $prices['regular_price'] );
   if ( $min_price !== $max_price || ( $product->is_on_sale() && $min_reg_price === $max_reg_price ) ) {
      $price = 'From: ' . wc_price( $min_price ) . $product->get_price_suffix();
   }
   return $price;
}

You may also like