Home / Blog / How To Disable Variable Product Price Range In WooCommerce
Disable Variable Product Price Range In WooCommerce

How To Disable Variable Product Price Range In WooCommerce

When you are a store owner, you can guess a similar scenario using reverse psychology. So, when you place a higher range, customers will surely bounce from your product page and you lose your potential sales. Thus, a common strategy would be to show the minimum price of the range. If you are a WooCommerce store owner, you cannot modify the price range format of variable products, sad but true!

WooCommerce is one of the most popular eCommerce solutions for WordPress. Currently, it powers almost 28% of all the online stores around the world. Impressive, right?

Today, we are not going to discuss that. Instead, we are here with a valuable piece of tutorial for store owners using WooCommerce. We will show you – how easily you can change the behavior of the price range format that WooCommerce stores display for Variable Products.

In WooComerce, there are many types of products. Variable product variation are one of them and plays a vital role when you are trying to sell products with different variations.

It is possible in WooCommerce to create a single product with multiple sizes, colors, weight, etc. We can set different prices for the variations of your product. So, when we create a variable product with multiple prices, the price of the product is shown as a range on the product page. If you create a variable product with different prices.

How to Modify WooCommerce Variable Product Price Range

How To Disable Variable Product Price Range In WooCommerce

For the modification, we will need to do some custom coding. If you are confused about the file location and have less concept of coding it is better to add the code to your child theme function.php file.

The Simple & Easy Code that You Need to Insert :

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

This will show your Variable Product Price like this

Form: 100$

 

How To Disable Variable Product Price Range In WooCommerce

and you want to show your Variable Product Price without starting (From) paste this custom 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 ) );
$prod_price = $prod_prices[0]!==$prod_prices[1] ? sprintf(__(' %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(__(' %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;
}

this will show link this

How To Disable Variable Product Price Range In WooCommerce

About wpscriptor

WP Scriptor is WordPress Trainer and Developer in the Karachi, Pakistan area. We’re WordPress developer’s goal is to make the world of WordPress accessible to everybody. We publish weekly in-depth WordPress tutorials and WordPress techniques on the site and to our mailing list, and we link out to cool WordPress stuff elsewhere on the web most weekdays.

Check Also

WordPress Gutenberg Editor

WordPress Gutenberg Editor