Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

[WooCommerce] Disable Variable Product Price Range $100-$125

wordpress-freelancer-developer

Hi Friends,

I was recently working with WooCommerce website and my client want to hide the variable product price range. Instead of variable product price $100-$150, client just want to see From: $100. When customer goes in details page, he can see the actual price instead of variable product price.

Here is code to disable variable product price range of WooCommerce. Just copy and paste code in functions.php file.

 

 

 

 

 

add_filter( 'woocommerce_variable_sale_price_html', 'CI_remove_var_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'CI_remove_var_price', 10, 2 );
 
function CI_remove_var_price( $price ) {
$price = '';
return $price;
}

Once you place above code, it will disable all variable product price and show just one price on listing page, single page and all other places.

Other option is if you want to show customer lowest price and show them max price with cross line above it, here is code to place in functions.php file.

add_filter( 'woocommerce_variable_sale_price_html', 'CI_var_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'CI_var_price_format', 10, 2 );
 
function CI_var_price_format( $price, $product ) {
 
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
 
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
 
if ( $price !== $saleprice ) {
$price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
}
return $price;
}

Once you place above code, you can see the maximum price with cross line above it while minimum price will show on the page.

If you need any help, do not hesitate to post comment and we would love to help you out.

Share: