1. Home
  2. Help Center
  3. WooCommerce
  4. Customization
  5. Replace variable price range by chosen variation

If the product variants have different prices, WooCommerce will display the price range below the title and the selected price variant in another section near the add to cart button.

To replace the price range with the current price variant and remove the independent price variant, paste the following PHP snippet in /wp-content/themes/goya-child/functions.php

add_action('woocommerce_before_add_to_cart_form', 'selected_variation_price_replace_variable_price_range'); function selected_variation_price_replace_variable_price_range(){ global $product; if( $product->is_type('variable') ): ?><style> .woocommerce-variation-price {display:none;} </style> <script> jQuery(function($) { var p = 'p.price' q = $(p).html(); $('form.cart').on('show_variation', function( event, data ) { if ( data.price_html ) { $(p).html(data.price_html); } }).on('hide_variation', function( event ) { $(p).html(q); }); }); </script> <?php endif; }
Code language: JavaScript (javascript)

Was this article helpful?

Related Articles