0
votes

All the variants for each product have the same price. When I use following code, it's showing price for all the variants. How do i show price of only one (let's say first) variant?

{% for variant in product.variants %}
    <div class="tablecell pricecur">
       {{ variant.price | money }}
    </div>
    <div class="tablecell pricecom">
       {{ variant.compare_at_price | money }}
    </div>
{% endfor %}
1
it would definitely help to know what language / framework you are using (Django?). What is also not clear is what first_available_variant returns. If it only returns one value you wouldn't have to iterate over it. - Alexei Danchenkov
fixed the "first_available_variant" part. Copied from unsuccessful experiment. As for the framework, it says shopify in the title and tag. - AbrylCabryl

1 Answers

0
votes

You use the following code.

{{ product.first_available_variant.price | money }}

first_available_variant - returns the first variant that is available ( a.k.a it's quantity is larger than 0 )