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

Last updated - February 24, 2020

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?

60 COMMENTS

  1. I don’t know if this post is still active but I do hope for some value here…I want to implement exactly what just like Jonathan said in the first message but it’s not working.

    Usually what happens is that when the price on the product page is completely removed. I mean when only the variation price is active. In that case,
    1) The prices on category pages and shop pages also go away.
    2) Variations of the same prize products come into a problem.

    This is what I am looking for
    it’s helpful but I am not able to do exactly what I want to.

    1) “From price” should be visible in Category and shop pages.
    2) On the product page, only that price should be visible for which variation is selected. The minimum price should be visible only when no variation is selected. Once selected, the minimum price should go away.
    3) But it should not affect the product with variables of the same pice. That should stay unaffected.

    Any ideas, please? I feel exhausted as I have tried many snippets

    • Hi Charlie,

      Please check the below code.

      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>’;
      }

      if(! is_product()) {
      return $prod_price;
      }
      echo ‘<div class=”hidden-variable-price” >’.$prod_price.'</div>’;
      ?>
      <style>
      div.woocommerce-variation-price,
      div.woocommerce-variation-availability,
      div.hidden-variable-price {
      height: 0px !important;
      overflow:hidden;
      position:relative;
      line-height: 0px !important;
      font-size: 0% !important;
      }
      </style>
      <script>
      jQuery(document).ready(function() {
      jQuery(‘p.price’).html(jQuery(‘div.hidden-variable-price’).html());
      jQuery(‘input.variation_id’).change( function(){
      if(jQuery(‘input.variation_id’).val() != 0){
      jQuery(‘p.price’).html(jQuery(‘div.woocommerce-variation-price > span.price’).html());
      } else {
      jQuery(‘p.price’).html(jQuery(‘div.hidden-variable-price’).html());
      }
      });
      });
      </script>
      <?php
      }

      After adding this code please hard reload your product page once in case it fails to work.

  2. Hi,
    Thank you for the code. It’s not working quite as expected for me, the “from price” is still appearing on the variable product page. I want the “from price” on the category and other shop pages, and that’s working, but on the variable product page I just want a single price of that variation near the add to cart button. Can you see an error in the code that’s causing it to still appear please?

    //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 );

    if(is_product()) {
    return $v_price;
    }
    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 = ‘‘.$regular_price.$v_product->get_price_suffix() . ‘ ‘ .
    $prod_price . $v_product->get_price_suffix() . ”;
    }
    return $prod_price;
    }
    //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;
    }

    • Hi Jonathan,
      I can see you have added the below code outside the function. Please include the code snippet inside the function.

      if(is_product()) {
      return $v_price;
      }

  3. Hi
    This works great on my products with variations.
    But it does not work when I put in sale prices, then I have both regular prices and sale prices.
    Can you advice on how to solve this or maybe display the two prices (regular price and sale price) on separate lines?
    Reply

    • Hi Madalina,

      By changing the last IF block in a function, you can change the display of prices

      Please replace last IF block with below code
      1 – To remove regular price range
      if ( $prod_price !== $regular_price ) {
      $prod_price = ‘ <ins>’ . $prod_price . $v_product->get_price_suffix() . ‘</ins>’;
      }

      2 – To show Regular and Sale price in separate lines
      if ( $prod_price !== $regular_price ) {
      $prod_price = ‘<del>’.$regular_price.$v_product->get_price_suffix() . ‘</del><br> <ins>’ .
      $prod_price . $v_product->get_price_suffix() . ‘</ins>’;
      }

    • Hi Shashidhar

      I have tried both IF functions, but no change.
      Any ideas to solve this will be greatly appreciated.

    • Can you share the code that you have updated last? It is working on my end.

    • Hi Shashidhar

      Thank you very much for your time.
      This is what I have put in:

      //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(__(‘Fra: %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(__(‘Fra: %1$s’,’woocommerce’)
      , wc_price( $regular_prices[0] ) ) : wc_price( $regular_prices[0] );

      if ( $prod_price !== $regular_price ) {
      $prod_price = ” . $prod_price . $v_product->get_price_suffix() . ”;
      }
      return $prod_price;
      }

      And this is my price.php from the theme, I am not sure if it helps with anything

      global $product;

      $classes = array();
      if($product->is_on_sale()) $classes[] = ‘price-on-sale’;
      if(!$product->is_in_stock()) $classes[] = ‘price-not-in-stock’; ?>

      <p class="price product-page-price “>
      get_price_html(); ?>

    • Hi Madalina,

      The above code worked fine for me. I suspect there is a compatibility issue with other plugins code. You can check by deactivating other plugins or check if you have added any code in functions.php.
      Also, Change the priority(10 in our case) of our hooks and try.

    • Hi Shashidhar

      You were right, it was because of the plugin that I use, Category Discount.
      Thank you so very much for your help.

  4. Hi,

    I don’t know if you are still  answering questions. I will give it a chance. First of all thank you for the snippet. If I want to remove the From:$X from my shop page.

    Thanks,

    Johanne

    • Hi Johanne,
      Add the below code snippet at the beginning of the function.
      if(! is_product()) {
      return $v_price;
      }

  5. Hi, i’m trying to do some similar but a little different.
    I try your code and work well but i prefer to display something like “[minimum quantity] at [minimum price]”. Where minimum quantity is the selectable attribute.
    There is a way to do this?

    • Hi Marino,

      As you can see, we have used WooCommerce Hooks here:
      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 );

      You can simply return any HTML content to these hooks from the callback function.

      function lw_variable_product_price( $v_price, $v_product ) {

      return ‘<select><option>1</option><option>2</option></select>’;
      }

      the above code simply creates a select field with 1 and 2 as an option. In this way, you can modify these hooks as per your business requirements.

  6. Hello- trying to use the code but isn’t working. I have a product bundled with a variable product. I want to remove the “From Now “and “Then From” verbiage.

    Thank you

    • Hi Evan, unfortunately this code snippet will not work with Product Bundles.

  7. Hello,

    Thanks for posting this snip!

    I am having an issue that if all variations have the same price, the price is not displaying on the product screen. All other variations that have multiple prices are working fine.

    Hope you can help.

    Thanks,

    • Hi Michael.
      If all the variations have the same price, we generally don’t show ‘From’ text as WooCommerce also doesn’t show price range. If you still want to show ‘From’ text, use the below code.

      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 = sprintf(__(‘From: %1$s’, ‘woocommerce’),
      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 = sprintf(__(‘From: %1$s’,’woocommerce’)
      , 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;
      }

      Hope it helps.

  8. Hi Azhar, Thanks for your post.

    One of my variation’s price is $0 and obviously the result is “From: $0”.
    Do you how can I start with the next variation’s price (more than zero)?

    Please let me know and thank you very much.

    • Hi Rod,
      Please check the modified code below.

      //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($prod_prices[0] == 0){
      $all_variation_prices = $v_product->get_variation_prices();
      foreach($all_variation_prices[‘price’] as $index => $temp_price) {
      if($temp_price != 0) {
      $prod_prices[0] = $temp_price;
      break;
      }
      }
      }
      $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 );
      if($regular_prices[0] == 0){
      $all_variation_prices = $v_product->get_variation_prices();
      foreach($all_variation_prices[‘regular_price’] as $index => $temp_price) {
      if($temp_price != 0) {
      $regular_prices[0] = $temp_price;
      break;
      }
      }
      }
      $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;
      }

  9. Hello,

    I need to display the price range on all pages without the product page. The code in the comments dont work. Do you have any ideas i can do this? To hide only the price on product page?

    Thank You!

    • Hi Steffan,
      Add the below code snippet at the beginning of the function.
      if(! is_product()) {
      return $v_price;
      }

  10. how to hide just word from and keep the price ?

    • Hi Rawan,
      In the first code snippet of this article, you can notice ‘From: %1$s’. To remove the word “From” and just keep the price, remove the text “From” and just keep it as ‘%1$s’.

  11. I only want the price range to show in single product page. Every where else I like in category listing page or front page where products are list I want to show minimum price.
    What to do ?

    • Hi Viky,
      Add the below code snippet at the beginning of the function.
      if(is_product()) {
      return $v_price;
      }

  12. I am trying to:

    Change variable price to “FROM:£X”
    Show “FROM:£X” in CART (Upsells), CATALOGUE, CATEGORY PAGES, RELATED PRODUCTS
    Hide “FROM:£X” in single product page

    This is my snippet, everything works ok BUT it will not hide “FROM:£X” in single product page – Have you got any ideas?

    //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 = ‘‘.$regular_price.$v_product->get_price_suffix() . ‘ ‘ .
    $prod_price . $v_product->get_price_suffix() . ”;
    }
    return $prod_price;
    }

    //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()) && !(is_product_category()) ) {
    return ”;
    }
    // return regular price

    return $v_price;
    }

  13. hi but it not work in combo product page

    • Hi Arun,
      The code snippet will work only for variable products. If you have a variable product in your combo product, the code snippet will work for the variable product. The price range you see for the grouped product is not related to any variations, but are just the price range of all the products in the combination.

  14. Wow, that worked great. Many thanks for sharing

  15. Thanks Code is great. But I want the From $$ price to show up on the shop or category page. I only do not want it to show on the product page. Can you please advise.

    • Hi Jay,

      Add the below code at the beginning of the function.
      if(is_product()) {
      return $v_price;
      }

    • Hi Shashidhar,
      That did not work for what I wanted but I was able to achieve it by slightly modifying the code. //Hide “From:$X”

      This code will

      Shop page – From $X will show
      Product Category page – From $X will show
      Individual Product page – From $X will NOT show

      Here is the code
      /**
      * Hide “From:$X” only on the product page
      */
      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()) && !(is_product_category()) ) {
      return ”;
      }
      // return regular price

      return $v_price;
      }

    • 👍

    • Hi! Thanks for the snippet!
      Please tell me how to make the price displayed in the “related products”?

    • Hi Mark, It is working for related products when we tested. Please note, it won’t work if you are checking on a simple product.

    • Hi Jay, I tried your code but cannot get “Individual Product page – From $X will NOT show” to work

      //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 = ‘‘.$regular_price.$v_product->get_price_suffix() . ‘ ‘ .
      $prod_price . $v_product->get_price_suffix() . ”;
      }
      return $prod_price;
      }

      //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()) && !(is_product_category()) ) {
      return ”;
      }
      // return regular price

      return $v_price;
      }

  16. hey I use WooCommerce Currency Switcher on my site. I have set dollar to rupee value as 68. After using the above snippet the price prices get way high (image – https://ibb.co/x3ZSKJf), is it something in the snippet or in currency converter. rest your snippet works like a charm:)

    • please check for the striked prices…

  17. Hi there. Excelente snippet works great! Just one question i´m hidding the from: on my product page. Do you know how to hide it in the shop page and display there the price of selecte variation instead of the from:

    Many thanks and my best regards

    • Hi,
      Remove ‘From:’ in both the places of the code snippet. Make sure the strings within the single quote after removing ‘From:’ are same. i.e, there should not be any extra space or any other character.

  18. 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;
      }

  19. 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.

  20. 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.

    • I have the same problem. If I have the same price, no price is being displayed.
      And the second problem. No price in normal product no variations. Any suggestions?

    • Hi Michaeal, as mentioned in a previous comment, if all the variations have the same price, WooCommerce doesn’t show a price when you select attributes. Also, it won’t show the price range.

  21. 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;
      }

  22. 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.

  23. 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