This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How To Change Variable Product Price Range in WooCommerce

Updated on June 18, 2021

2 Min Read

Before WooCommerce 2.1, the range of the prices for products were not displayed. Thus instead of showing “From  55-60”, the price showed up as “Starting from  55”.

Variable Product Price Range

In many cases, the store owners do not wish to display the full range of price. However, this is no longer the option in the newer versions of WooCommerce.

test product

 

To implement this, you need to add the following code snippet to the functions.php of your theme. This file is located in the theme folder.

function cw_prc_varb( $val_price, $product ) {

    $prefix = sprintf('%s: ', __('From', 'through'));
    $cw_reg_min_prc = $product->get_variation_regular_price( 'min', true );
    $cw_min_sale_prc    = $product->get_variation_sale_price( 'min', true );
    $cw_prc_max = $product->get_variation_price( 'max', true );
    $cw_prc_min = $product->get_variation_price( 'min', true );

    $val_price = ( $cw_min_sale_prc == $cw_reg_min_prc ) ?
        wc_price( $cw_reg_min_prc ) :
        '<del>' . wc_price( $cw_reg_min_prc ) . '</del>' . '<ins>' . wc_price( $cw_min_sale_prc ) . '</ins>';

    return ( $cw_prc_min == $cw_prc_max ) ?
        $val_price :
        sprintf('%s%s', $prefix, $val_price);

}

add_filter( 'woocommerce_variable_sale_price_html', 'cw_prc_varb' );
add_filter( 'woocommerce_variable_price_html', 'cw_prc_varb' );

Output

test product output

Conclusion

In this tutorial I have discussed how you could easily change the present behavior of  the display of the price range on WooCommerce stores. If you need any help with the implementation of this idea, do leave a comment below.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Owais Khan

Owais works as a Marketing Manager at Cloudways (managed hosting platform) where he focuses on growth, demand generation, and strategic partnerships. With more than a decade of experience in digital marketing and B2B, Owais prefers to build systems that help teams achieve their full potential.

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour