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

Last updated - April 28, 2022

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:

90 COMMENTS

  1. Hi Team, I want to change the variable product price range format to (min price) on the SHOP PAGE (not the single product page!)
    Any suggested code snippet please?

  2. I tried a few other codes and yours was the only one that worked! Is there a way to make that change on the archive page as well? Right now this is only affecting the product pages.

    Thanks!

    • Great, that you could solve the issue. yes, you can try checking it. Let us know if you face any issues.

  3. Hi,

    How can I only show the bigger price all the time at the product page and when I select a variable product the price changes for that product. Not that price that is hidden and appears after we select the variable product, that I don’t want it to show at all time. I just want one big price showing all the time and changing when I select a variable product.

    Thanks!!

  4. Hello,
    can you help me with the code where I dont want to display the price in the catlog as well as shop page

  5. not sure if you still reply but here i go, so i am looking to when a user chose a variation the actual price to not appear i mean the one that has the buy now button drop and appear on top…

    so essentially i want to change only the from price, not the buy now drop and another price appear… on top on the video i show the price is below the variations which is shame.

    if you go into alixpress and choose some variation products you will see only the price “from” change not button and appear the actual price is shown

    • Hi Jim,

      can you, I did not understand your concern. Please share for more details. If possible, with screenshots.

  6. Thank you very much for your tutorial
    It really saved me and made me happy!
    I wish you more success!

    • Glad it helped you. Stay tuned and subscribe to our newsletter for more insights.

  7. Hello,
    Can you help me changing the default string of subscription variation product?
    Currently Using Custom Price String For Woocommerce Subscription But No Luck.

  8. How do we stop this from affecting simple products? Right now everything with variable products works wonderful.
    1. Category Pages show From $X
    2. Variable Product pages show From $X until a variation is chosen, then it shows the price of that selected variation.
    3. Simple products show the last variable product “From $X” a split second after showing the proper price. It’s getting overridden by the JQuery code in the comments above when it shouldn’t.

    • I’ve actually solved the issue myself. I ended up using actions specifically on woocommerce_before_single_product and woocommerce_single_product_summary instead of filters across the whole site. Paired with the jQuery it accomplishes everything I wanted it to do for both simple and variable products. I did use a filter based on code here to display the From: $X in shop/category pages.

    • This code snippet won’t affect simple products. and there is no jquery code in our snippet. Please let us know which jQuery code your referring?

  9. Hi,

    I tried both codes, and they worked fine for me.

    Just want to ask, I want to hide the product range for a particular product or product category.

    Please can anyone help me with it!

  10. Carlos martinez

    Great help 🙂 it worked for me

    Now I´m having an issue: how to do to make this “From” word translatable?

    I want to have the word “From” in english, but it should be translated to “Desde” in Spanish

    I´m using polylang, and I think I can add this code as a chain string in order to do that, but I don´t know how

    Any ideas?

    On polylang docs, I read I can add to functions php this function in order to work
    pll_register_string( $name, $string, $group, $multiline);

  11. When I add both codes to my site, the product category page prices also hide. Please suggest

    • Please check the codes you added correctly.

  12. Hi,
    I think I’m missing something. Trying to paste the codes above (the first one) in the function.php file (at the bottom) but I get the message that something went wrong and that it may not have been saved successfully and that I may have to do it manually in FTF…
    What am I missing? I copied everything from //Hide….. to the end.

    New to this and coding is like chinese, or russian, or hebrew or any other language that doesn’t use the latin alphabet 🙂

    Thank you in advance for any guidance

  13. Hello

    could someone help we with right snippet?

    I want:
    1. Shop page – save product range as it is (100 – 150 $)
    2. Single Product page – hide product range (100 – 150 $)
    3. Single Product page – show variable price of chosen variant

    Can anyone help me how to fix thing from 2. ?
    1. and 3. should stay as it is
    I will be grateful for help.

    • Hi Adrian,

      Check below code snippet.

      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 ) {
      if(is_product()) {
      return ”;
      }
      return $v_price;
      }

    • Hi haider,

      Please replace the last if block with below code

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

  14. Is there a way to just have the main price update based on the selected variable product instead of using the price that shows up below the dropdown? This is such a mess of woocommerce to not offer a way to use the main price and at the same time give the option to “show range price” or “show default product price”. So annoying.

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

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

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

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

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

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

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

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

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

    • hello,

      can you write full code to hide what Steffan wanted?

  24. 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’.

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

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

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

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

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

  30. 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…

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

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

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

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

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

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

  37. 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 to Tamara Miranda Cancel reply

Please enter your comment!
Please enter your name here