Tutorials

How to disable the price range in WooCommerce variable products

Do you want to disable the price range in WooCommerce variable products?

Most of the time users browse different online stores to find their desired products. When they are able to find the products they look for the product price. If the product is a variable product that means there are different variations available for the product, then the maximum website shows a price range for the products.

Suppose you want to buy a bag from an online store and there are different sizes and colors available for your selected bag. The price also varies for different variations. When the user selects the size and color they will see the actual price but before that, they will see the price range. Here, if the price range is high and out of their budget, most users avoid selecting the size and color to see the exact price. So selecting a higher range can bounce your potential customers from your store.

WooCommerce is one of the best plugins available for an online store. It offers you so many features and functionalities to run your online shop including variable products. By default, WooCommerce will show a price range in your valuable products but the plugin doesn’t provide any options to modify it.

So here in this article, we will show you to disable the price range in WooCommerce variable products.

Variable products in WooCommerce

There are different types of products available in WooCommerce such as –

  • Simple product
  • Grouped product
  • External/Affiliate product
  • Variable product

All the product types are very important to an online store. Variable product type is also important if you want to sell different variations of a product. Using a single product you can create different variations of that product like multiple sizes with multiple colors.

On the other hand, you can also set different prices for different variations. So when you select a different price it will show a price range on your product page.

disable the price range in WooCommerce variable products

It’s not a good practice to show the price range product page but unfortunately, WooCoomecer doesn’t let you modify the price range area. But you can modify it in other ways. So let’s see the way to modify the price range of variable products.

Disable the price range in WooCommerce variable products

To disable the price range in WooCommerce you need to add some custom coding to your website. If you are not familiar with coding then you can create a child theme and add the code there. This will not affect your main website functionalities. You need to add this code to your function.php file. 

Go to Appearance > Theme Editor and then you will find the function.php file at the right sidebar. 

disable the price range in WooCommerce variable products

Now add this code snippet to this file.

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

Update the file and go to the products to see what happens. This will remove the range from your product price area.

disable the price range in WooCommerce variable products

But it will also show the starting price of the product, you can remove this too. For this again open up the function.php file and add this code 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;
}

Wrapping up

Following the process, you will be able to disable the price range in your online store for variable products. You can see our other articles to learn How to reset WordPress passwords from phpMyAdmin

How to redirect 404 pages to the home page in WordPress

How to add special characters in WordPress

We hope this article will help you. If you like this article please like our Facebook Page to stay connected.

You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *