How to display the price of a selected variation on a WooCommerce product?

I am working with a custom product page, which uses a number of different attributes with different prices for each variation. But I’m having issues pulling the active variation price based on the selected variation.

I tried this solution:
http://webroxtar.com/2013/07/get-regular-and-sale-prices-of-product-variations-in-woocommerce/

Which I can get to pull all prices by looping — but cannot figure out how to call the correct price from the array when a variation is selected.

In case it helps, this is what I am using to pull the attributes and their names:

<?php foreach ($attributes as $attribute_name => $options) : ?>
<div class="filter">
<div class="value">
   <?php
    $selected = isset($_REQUEST['attribute_' . sanitize_title($attribute_name)]) ? wc_clean(urldecode($_REQUEST['attribute_' . sanitize_title($attribute_name)])) : $product->get_variation_default_attribute($attribute_name);
    wc_dropdown_variation_attribute_options(array('options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected));
            ?>
 </div>
 <div class="labels clearfix">
   <div class="label"><?= wc_attribute_label($attribute_name); ?></div>
     <div class="attribute_label"></div>
 </div>
</div>

Read more here: How to display the price of a selected variation on a WooCommerce product?

Leave a Reply

Your email address will not be published. Required fields are marked *