Home / Blog / WooCommerce: Display Price For Variable Product With Same Variations Prices

WooCommerce: Display Price For Variable Product With Same Variations Prices

Recently, I was asked to add a few variations to a product in WooCommerce eCommerce system. I added two attributes with different options to create the variations. The product needed to display the same price, no matter which variation is selected by customers. That sounds simple right? Yes, but by default, WooCommerce product page does not display the price if a variable product has many variations with the same prices. This is because the minimum and maximum prices are the same. Fortunately, you can force it to display the price by add the following snippet to your functions.php file.

// Display Price For Variable Product With Same Variations Prices
add_filter('woocommerce_available_variation', function ($value, $object = null, $variation = null) {
	if ($value['price_html'] == '') {
		$value['price_html'] = '<span class="price">' . $variation->get_price_html() . '</span>';
	}
    return $value;
}, 10, 3);

Before:

woocommerce-variable-same-price-01

After:
woocommerce-variable-same-price-02

Tags: ,