How to hide Price range for WooCommerce Variable Products? (with Video)

Last updated - June 26, 2019

Every now and then we wish to tweak some of the features of WooCommerce. If you are selling variable products in your store, then you might have noticed the price range for the given product(s). While some of us seem fine with it, there are few who would want to hide the price range and show the product price when the respective variation is selected.

In this article, I’ll share code snippets that will help you alter the variable price range information for WooCommerce Variable Products.

Hide Price range for WooCommerce Variable Products

Following is a sample screenshot showing the default setup for WooCommerce variable products.

Hide Price Range for WC Variable Product | Default Variable price range setup
Default Variable price range setup

The Code snippet

Add the following code snippets at the end of the Themes function (functions.php) file of your currently activated website theme. You can find this file in Appearance > Editor > select functions.php file listed in the right sidebar menu.

//Hide Price Range for WooCommerce Variable Products
add_filter( 'woocommerce_variable_sale_price_html', 
'lw_variable_product_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 
'lw_variable_product_price', 10, 2 );

function lw_variable_product_price( $v_price, $v_product ) {

// Product Price
$prod_prices = array( $v_product->get_variation_price( 'min', true ), 
                            $v_product->get_variation_price( 'max', true ) );
$prod_price = $prod_prices[0]!==$prod_prices[1] ? sprintf(__('From: %1$s', 'woocommerce'), 
                       wc_price( $prod_prices[0] ) ) : wc_price( $prod_prices[0] );

// Regular Price
$regular_prices = array( $v_product->get_variation_regular_price( 'min', true ), 
                          $v_product->get_variation_regular_price( 'max', true ) );
sort( $regular_prices );
$regular_price = $regular_prices[0]!==$regular_prices[1] ? sprintf(__('From: %1$s','woocommerce')
                      , wc_price( $regular_prices[0] ) ) : wc_price( $regular_prices[0] );

if ( $prod_price !== $regular_price ) {
$prod_price = '<del>'.$regular_price.$v_product->get_price_suffix() . '</del> <ins>' . 
                       $prod_price . $v_product->get_price_suffix() . '</ins>';
}
return $prod_price;
}

Thanks to our readers in the comment section who have helped us improve the code snippet. We have taken your valuable comments into consideration!

Here’s how the code snippet affects the variable product price range display.

Hide Price Range for WC Variable Product | Variation Price with Starting price specified
Variation Price with Starting price specified

Removing “From: $X”

While the code snippet given above in the article serves most of the purpose, you can choose to remove “From: $X” that specifies starting variation price as well.

To do this, add the following code snippet at the end of the functions.php file.

//Hide “From:$X”
add_filter('woocommerce_get_price_html', 'lw_hide_variation_price', 10, 2);
function lw_hide_variation_price( $v_price, $v_product ) {
$v_product_types = array( 'variable');
if ( in_array ( $v_product->product_type, $v_product_types ) && !(is_shop()) ) {
return '';
}
// return regular price
return $v_price;
}

Following screenshot shows how the starting variation price can be removed by applying the above code snippet.

Hide Price Range for WC Variable Product | Variation Price without Starting variation price
Variation Price without Starting variation price

Therefore, in this way, you can hide Price range for WooCommerce Variable Products.

You can also watch a quick video tutorial to understand this process.

Did this code snippet work for you? Do let us know in the comments.

 

Check out other articles for WooCommerce customization here.

Or continue exploring LearnWoo for amazing articles.


Suggested reading:

WooCommerce Product Variations – How to move Add to Cart button above Product short description?

13 COMMENTS

  1. Hi,

    thank you.
    I hid Prize in my shop page according to your code, how can i enable it?
    And second question i want to disable “From: ” and have only the minimum prize in shop page.

    In product page it is ok to have “From: ” but in shop page – not.
    Please help,
    Jacek

    • Hi Jacek,
      I did not understand the first question, please elaborate.

      Regarding the second question, use the below code.

      //Hide Price Range for WooCommerce Variable Products
      add_filter( ‘woocommerce_variable_sale_price_html’,
      ‘lw_variable_product_price’, 10, 2 );
      add_filter( ‘woocommerce_variable_price_html’,
      ‘lw_variable_product_price’, 10, 2 );

      function lw_variable_product_price( $v_price, $v_product ) {

      // Product Price
      $prod_prices = array( $v_product->get_variation_price( ‘min’, true ),
      $v_product->get_variation_price( ‘max’, true ) );
      if(!is_shop()) {
      $prod_price = $prod_prices[0]!==$prod_prices[1] ? sprintf(__(‘From: %1$s’, ‘woocommerce’),
      wc_price( $prod_prices[0] ) ) : wc_price( $prod_prices[0] );
      }
      else {
      $prod_price = $prod_prices[0]!==$prod_prices[1] ?
      wc_price( $prod_prices[0] ) : wc_price( $prod_prices[0] );
      }

      // Regular Price
      $regular_prices = array( $v_product->get_variation_regular_price( ‘min’, true ),
      $v_product->get_variation_regular_price( ‘max’, true ) );
      sort( $regular_prices );
      if(!is_shop()) {
      $regular_price = $regular_prices[0]!==$regular_prices[1] ? sprintf(__(‘From: %1$s’,’woocommerce’)
      , wc_price( $regular_prices[0] ) ) : wc_price( $regular_prices[0] );
      }
      else {
      $regular_price = $regular_prices[0]!==$regular_prices[1] ? wc_price( $regular_prices[0] ) : wc_price( $regular_prices[0] );
      }

      if ( $prod_price !== $regular_price ) {
      $prod_price = ‘<del>’.$regular_price.$v_product->get_price_suffix() . ‘</del> <ins>’ .
      $prod_price . $v_product->get_price_suffix() . ‘</ins>’;
      }
      return $prod_price;
      }

  2. Thanks for posting this. I found the code very helpful. In my use case though, I actually needed to display the Maximum price because the lower variation price is the price of a sample of a product we sell by the square meter. Customers are only really interested in the maximum price on our site.

    So I modified the function as follows:

    function lw_variable_product_price( $v_price, $v_product ) {

    // Regular Price
    $v_prices = array( $v_product->get_variation_price( ‘min’, true ),
    $v_product->get_variation_price( ‘max’, true ) );
    $v_price = $v_prices[0]!==$v_prices[1] ? sprintf(__(‘Per SQM: %1$s’, ‘woocommerce’),
    wc_price( $v_prices[1] ) ) : wc_price( $v_prices[0] );

    return $v_price;
    }

    I just deleted the clause on the sale price – I’m not sure if we’ll run into problems if we ever use sale prices. Sale prices will not apply to samples in any case.

    I’d be interested in any thoughts you may have on the above.

    Thanks

    • Hi Matt, thanks for sharing the code snippet!
      Yes, your code will work for Regular price showing the maximum price, instead of the minimum product price in the variation (as given in our original code snippet).
      As for the Sale price code section, it is supposed to be for Regular price (when a Sale price is given for the variable products) and the previous section is for Product price (when only Regular price is given for variable products).
      We have updated the comment line and variable names for easy understanding.

  3. The Removing “From: $X” code works great except when there is a variable product where the variations are the same price. Meaning, when I select a variation the variable price should display below but in the case where the variations have the same price, no price is being displayed.

    Any suggestions?

    • Hi,
      Since all the variants have the same price, WooCommerce doesn’t show any price below the attribute selector.

  4. Hi, the second snippet hides price on the product page AND on the product archive also.
    I need to show the price on the product archive, and hide on product pages only.
    How can I do that?

    • Hi ,
      You can use the below snippet.
      //Hide “From:$X”
      add_filter(‘woocommerce_get_price_html’, ‘lw_hide_variation_price’, 10, 2);
      function lw_hide_variation_price( $v_price, $v_product ) {
      $v_product_types = array( ‘variable’ );
      if ( in_array ( $v_product->product_type, $v_product_types ) && !(is_shop()) ) {
      return ”;
      }
      // return regular price
      return $v_price;
      }

  5. WO WO WOOO Guys tanks for this information!!!
    thanks to its code I could hide the variable price and translate the From to Desde (Spanish)
    How Could I edit the From / desde Text color?
    Ref: https://prnt.sc/n889jo

    Thank you in advance for your support and your page and your spectacular work.

    • Hi,
      You can replace the text ‘From:’ with <span style=”color:red;”> From: </span> . And you can edit ‘red’ with the color you want.

  6. Hello, i tried using the second code but it didn’t work.
    //Hide “From:$X”
    add_filter(‘woocommerce_get_price_html’, ‘lw_hide_variation_price’, 10, 2);
    function lw_hide_variation_price( $v_price, $v_product ) {
    $v_product_types = array( ‘variable’ );
    if ( in_array ( $v_product->product_type, $v_product_types ) ) {
    return ”;
    }
    // return regular price
    return $v_price;
    }

    • Hi
      What are you getting instead? Is it an error or the prices are getting displayed just the same. If it is an error please use $v_product->get_type() instead of $v_product->product_type and see if it works.

    • Hi,

      The product type for a WooCommerce Variable type product is ‘variation’. Use $product->get_type() == ‘variation’.
      Use,
      $v_product_types = array( ‘variation’ );
      if ( in_array ( $v_product->get_type(), $v_product_types ) ) {
      return ”;
      }
      Check it will work.

LEAVE A REPLY