• Hi fellow WordPressers,

    I would like some help with figuring out how to display a minimum and maximum price per product in my catalog. Right now it only shows one price. I found the function (from the Woocommerce Plugin) that displays the price:

    /**
     * Format the price with a currency symbol.
     *
     * @param float $price
     * @param array $args (default: array())
     * @return string
     */
    function wc_price( $price, $args = array() ) {
    	extract( apply_filters( 'wc_price_args', wp_parse_args( $args, array(
    		'ex_tax_label'       => false,
    		'currency'           => '',
    		'decimal_separator'  => wc_get_price_decimal_separator(),
    		'thousand_separator' => wc_get_price_thousand_separator(),
    		'decimals'           => wc_get_price_decimals(),
    		'price_format'       => get_woocommerce_price_format()
    	) ) ) );
    
    	$negative        = $price < 0;
    	$price           = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) );
    	$price           = apply_filters( 'formatted_woocommerce_price', number_format( $price, $decimals, $decimal_separator, $thousand_separator ), $price, $decimals, $decimal_separator, $thousand_separator );
    
    	if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $decimals > 0 ) {
    		$price = wc_trim_zeros( $price );
    	}
    
    	$formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, get_woocommerce_currency_symbol( $currency ), $price );
    	$return          = '<span class="amount">' . $price . '</span>';
    
    	if ( $ex_tax_label && wc_tax_enabled() ) {
    		$return .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
    	}
    
    	return apply_filters( 'wc_price', $return, $price, $args );
    }

    Maybe I need to tweak or completely override the above code?

    I tried the following piece of code in my functions.php file and this did not have any effect other than adding the “Min:” text before the price. The prices still remained exactly the same as before.

    add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
    
    function custom_variation_price( $price, $product ) {
    
    $price = 'Min: ';
    
    $price .= woocommerce_price($product->min_variation_price);
    
    return $price;
    }

    Please excuse if I haven’t made myself clear enough as this is my first post. Any help would be very much appreciated.

    I am using WooCommerce Version 2.5.5.

  • The topic ‘WooCommerce – Display Max and Min Prices per Product’ is closed to new replies.