In wordpress WooCommerce, when i add a Variation Product, variation is set only by Two colors,
Starwhite = 9000 Ivory = 15000
On the Single Product page, I get to see price mentioned twice, as shown in screenshots.
I want to retain the price defined in variation. Remove the other one.
The price which is not required is showing up under the div below
<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer"> <p class="price"><span class="amount">Rs.9,000.00</span>–<span class="amount">Rs.15,000.00</span></p> <meta itemprop="price" content="9000" style=" /* display: none; */ "> <meta itemprop="priceCurrency" content="INR"> <link itemprop="availability" href="http://schema.org/InStock"> </div>
But when i mark it has display none or visibility hidden, the price from variation is also gone..
1st Color Variation settings:
2nd Color Variation settings:
Also, there are times when i use Simple Product on the website, so any changes suggested should not impact simple product settings.
If i have to make any changes in the code, what should be the code and under which php files should it be changes.
Advertisement
Answer
I believe the file you need to edit is “/single-product/price.php”, you should have a copy of that file in your theme folder (/your-theme/woocommerce/single-product/price.php), if not you can copy it there from /wp-content/plugins/woocommerce/templates/
Change:
<p class="price"><?php echo $product->get_price_html(); ?></p>
To:
<?php if( $product->is_type( 'simple' ) ){ ?><p class="price"><?php echo $product->get_price_html(); ?></p><?php } ?>
That will make it only display the price for Simple Products. The other price display that changes when you select a different variation is set in /single-product/add-to-cart/variable.php so that will be unaffected.