{% if product.is_parent %}
<ul class="price-variants" id="prices-display">
{% for child in product.children.all %}
{% purchase_info_for_product request child as thekid %}
<li><strong>{{ child.get_title|title }} <p class="price_color">{{ thekid.price.incl_tax|currency:session.price.currency }}</p></strong></li>
{% endfor %}
</ul>
{% endif %}
This will give you the prices and variants displayed simultaneously.
Now to display only the correct price for the selected variant we add a displayVariantPrice(); call to the click event handler for each option field in the select element, go to templates>partials>form_field.html and replace the line on line 33 (may not be exactly line 33 as my files have been edited):
{% render_field field class+="form-control" %}
with:
{% render_field field class+="form-control text-capitalize" onclick="displayVariantPrice();" %}
Now to display the correct price info in the product info table, go to catalogue>detail.html.
above the line:
{% if session.price.exists %}
add the following:
{% if product.is_parent %}
{% for child in product.children.all %}
{% purchase_info_for_product request child as thekid %}
<tr class="variant-{{ child.title|slice:":5" }} product-info-pricing">
<th>{% trans "Price (excl. tax)" %}</th><td>{{ thekid.price.excl_tax|currency:session.price.currency }}</td>
</tr>
{% if thekid.price.is_tax_known %}
<tr class="variant-{{ child.title|slice:":5" }} product-info-pricing">
<th>{% trans "Price (incl. tax)" %}</th><td>{{ thekid.price.incl_tax|currency:session.price.currency }}</td>
</tr>
<tr class="variant-{{ child.title|slice:":5" }} product-info-pricing">
<th>{% trans "Tax" %}</th><td>{{ thekid.price.tax|currency:session.price.currency }}</td>
</tr>
{% endif %}
{% endfor %}
{% elif session.price.exists %}
Note the last line of the snippet. We add an 'elif' instead of just an 'if' to the line I asked you to paste in the snippet above of.
Then add the displayVariantPricing script to the templates>catalogue>detail.html in a {{ block extrascripts }} at the bottom of the template:
{% block extrascripts %}
{{ block.super }}
<script>
$(document).ready(function() {
displayVariantPrice();
});
function displayVariantPrice() {
$('#prices-display li').each(function(){
$(this).hide();
if ($(this).text().toLowerCase().indexOf($('#id_child_id').find(":selected").text()) >= 0){
var variant = $('#id_child_id').find(":selected").text().substring(0,5);
$('.product-info-pricing').hide();
$('.variant-'+variant).show();
$(this).show();
}
});
}
</script>
{% endblock %}
That code hides the unselected variant prices and only makes visible the selected variant price.
All that is left is one style to add:
.price-variants {
padding-left: 0px;
}
Which brings the variant price being displayed back in line with where the price originally appears.
I think that is everything, hope it helps!
Andrew