Force WooCommerce to always show selected variation price

A few versions ago, WooCommerce changed the price display for variable products slightly. Normally, at the top of the product page, under the title, you will see the price range (min to max) for the product. Then, when you select a variation, the price for that specific variation would show above the Add to Cart button. However, with the change they made, if ALL variations have the same prices (regular AND sale prices are all the same for all variations), then the price above the Add to Cart button is never shown. My guess is that since the single price is now shown below the title, it would be redundant to show it again above the Add to Cart button?

However, not all users like this change, and they want the variation price to always show above the Add to Cart button. Also, in some cases where some plugins alter the prices (or have custom price fields) for different users, such as my Wholesale Ordering and User Role Pricing plugins, you could possibly have different custom prices for variations even though you set all the regular/sale prices the same. In that case, the custom price for the specific variation might not show. I have found the function and corresponding filter hook that WooCommerce uses to decide if variation prices should be shown or not. Version 3.1.1 of Wholesale Ordering and version 2.1.1 of User Role Pricing both tap into those hooks and check the custom prices for the current user to decide if the variation prices should be shown or not, to remain consistent with how WooCommerce now does things.

If, instead, you want to override this and make sure that individual variation prices are ALWAYS shown above the Add to Cart button when a variation is selected, all you need to do is tap into that WooCommerce filter hook and set up a function that always returns a true value. Just make sure you set the priority high enough to override any values for this set by other plugins (such as mine).

Here is a code snippet you can copy and paste into your child theme’s functions.php file to accomplish this:

function ssp_always_show_variation_prices($show, $parent, $variation) {
return true;
add_filter( 'woocommerce_show_variation_price', 'ssp_always_show_variation_prices', 99, 3);