Connect with us

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

wordpress

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

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.

No votes yet.
Please wait...
READ  [PHP] Fatal error: Can’t use method return value in write context

We are a WordPress plugin developer company that focuses on useful WordPress plugin creation and empowering people to earn passive incomes from their blogs. We build unique and groundbreaking plugins that will revolutionize your blog!

Click to comment

Leave a Reply

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

More in wordpress

Sign up for our newsletter and get a free affiliate e-book!


About Me:

Szabi Kisded

Hi, my name is Szabi and I'm documenting my journey selling plugins on CodeCanyon. I will show you every step of it: learning to code, plugin ideas, WordPress stuff and more. Read more…

Mega Plugin Bundle:

CodeCanyon Portfolio:

Learn to Code Plugins:

Latest Promotions:

Recommended Theme:

Start Your Own Blog:

Recommended VPN Service:

Translate Your Blog:

AdSense Alternative:

Best Article Spinner:

Popular Posts:

Latest Posts:

To Top

Privacy Preference Center

      Necessary

      Advertising

      Analytics

      Other