Problem:
On WooCommerce 3, the variable product page layout includes an unsightly price range below the product title. This can be confusing and uninformative, especially when it remains unchanged after selecting a variation.
Solution:
To replace the price range with the chosen variation price and ensure it updates accordingly:
Remove the Unwanted Price:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
Insert the Variable Price without Range and Show the Lowest Price:
add_action( 'woocommerce_single_product_summary', 'replace_variation_single_price', 10 );
Copy the Variable Price into a Hidden Container:
echo '<div class="hidden-variable-price">' . $price . '</div>';
Hide the Chosen Variation Price and Availability:
div.woocommerce-variation-price, div.woocommerce-variation-availability { height: 0px !important; overflow: hidden; line-height: 0px !important; font-size: 0% !important; }
Use jQuery to Update the Price:
$('select').blur(function() { if ($('input.variation_id').val()) { $('p.availability').remove(); $('p.price').html($('div.woocommerce-variation-price > span.price').html()).append('<p class="availability">' + $('div.woocommerce-variation-availability').html() + '</p>'); } else { $('p.price').html($('div.hidden-variable-price').html()); if ($('p.availability')) { $('p.availability').remove(); } } });
Additional Notes:
The above is the detailed content of How to Replace the Price Range with Chosen Variation Price in WooCommerce 3?. For more information, please follow other related articles on the PHP Chinese website!