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.

📣 Join our live AMA on the Future of Page Builders with Brizy's CEO! Register Now →

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 Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at [email protected]

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

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

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now