Professional Website Design at Your Budget | Call us - 01750-994707

How to hide price range for woocommerce variable products

WooCommerce, one of the most popular e-commerce platforms, offers powerful features to enhance product presentation and customization. However, when it comes to variable products with price ranges, some merchants may find themselves grappling with the challenge of displaying multiple prices, which can potentially confuse or deter potential buyers.

Why hiding the price sometimes is important?

When you are displaying product prices for the variable products then customers will think this product price is higher. Customers might not notice the variable of this product at first look. To avoid this confusion sometimes merchants need to hide the price range.

How to hide price range using a plugin

Install Variation Price Display Range for WooCommerce on WordPress and Active it.

How to hide price range using a plugin

If you want to disable from starting before the price then disable Add From option

disable from starting before the price

How to Disable Variable Product Price Range

Login to your WordPress admin dashboard and Appearance> Theme editor > Function.php. Go to the bottom of the code and paste this code and save it.

//Hide Price Range for WooCommerce Variable Products by xdcoder.com

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;
}
How to Disable Variable Product Price Range

How to remove from before the product price

You might notice after hiding the product price range now there are product starting prices.

If your product price range was $22-100; now it’s showing from $22. If you want to delete this then replace the above code with this code.

//Hide Price Range From for WooCommerce Variable Products by xdcoder.com

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] ? 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] ? 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;
}

Leave a Comment