Chat with us, powered by LiveChat

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.

WordPress 5.0 is out. Test all the great new features before upgrading your Live website. Read How!

How to Change Variable Product Price Range in WooCommerce

Updated on October 3, 2017

2 Min Read
Reading Time: 2 minutes

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

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 owais.alam@cloudways.com

Be the first to check out WordPress 5.0

Use our Staging feature before upgrading your website to WordPress 5.0.

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

THERE’S MORE TO READ.