I need to change something here to show default variation price on my store page:
<div class="deal-part2-details">
<?php
if($product->get_type() == "simple"){
?>
<h5><?php echo get_field('network_price_text',$p_id); ?> <?php echo $currency; echo $product->regular_price; ?>pm</h5>
<h5 class="our-price"><?php echo get_field('our_price_text',$p_id); ?> : <?php echo $currency; echo $product->sale_price; ?>pm</h5>
<h6><?php echo get_field('upfront_cost',$p_id); ?> <?php echo get_field('upfront_cost_text',$p_id); ?></h6>
<?php
}else{
$product_variations = $product->get_available_variations();
$variation_product_id = $product_variations [0]['variation_id'];
$variation_product = new WC_Product_Variation( $variation_product_id );
?>
<h5 class="network-price"><?php echo get_field('network_price_text',$p_id); ?> <?php echo $currency; echo $variation_product->regular_price; ?>pm</h5>
<h5 class="our-price"><?php echo get_field('our_price_text',$p_id); ?> : <?php echo $currency; echo $variation_product->sale_price; ?>pm</h5>
<!--<?php if ( $price_html = $product->get_price_html() ) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif; ?> -->
<h6><?php echo get_field('upfront_cost',$p_id); ?><?php echo get_field('upfront_cost_text',$p_id); ?></h6>
<?php
}
?>
</div>
Would you be able to help me?
2
Answers
I just change code like that, and working for me:
For that point I just add two variable:
And then I activated them here:
I made these changes in my loop-start.php This is my simple solution and working pretty well.
Solution
Step1:
1st you can edit variable product & select variation values. Which variation
you want shown on product page Default Form Values See the screenshot Select Default value screenshot
Step:2
Then go to your active theme or child theme
functions.php
file put below code.It’s 100% working
Thanks