Product Archive, Product Page

WooCommerce Change Variable Product Price Range Display

WooCommerce Change Variable Product Price Range Display

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

If you wish to customise how variable product prices are displayed on both the Product Archive and Single Product templates, then this guide is for you. In this example, we remove the dash between the two prices and add the test “From” and “to” for a better user experience. This custom text makes it a little clearer that there are product variations which will determine the price of the product.

/**
* Snippet Name:		Customise the price range display of variable products with text
* Snippet Author:	ecommercehints.com
*/
add_filter( 'woocommerce_get_price_html', 'ecommercehints_change_variable_price_range_display', 10, 2 );
function ecommercehints_change_variable_price_range_display( $price, $product ) {

    if( ! $product->is_type('variable') ) return $price;
    $prices = $product->get_variation_prices( true );

    if ( empty( $prices['price'] ) )
    return apply_filters( 'woocommerce_variable_empty_price_html', '', $product );

    $min_price = current( $prices['price'] );
    $max_price = end( $prices['price'] );

    return apply_filters( 'woocommerce_variable_price_html', 'From ' . wc_price( $min_price ) . $product->get_price_suffix() . " to " . $max_price, $product );
}

Snippet Benefits

  • Customise the view of prices on variable products on the product archive and single product templates.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER