Relativity
Relativity

Reputation: 137

Item cart price and compare price duplicating

If I have more than one variant the price and compare price duplicate, say I have Black and tall variants, it would be $200 two times next to each.

How can I only show it once?

This is my code:

{% assign beforePrice = priceCompare | times: item.quantity %}

{{ item.variant.options[forloop.index0] }} {{ item.product.price[forloop.index0] }}

{% if item.product.compare_at_price > item.product.price %} {{ beforePrice | money }} {% endif %}

Upvotes: 0

Views: 599

Answers (1)

mikenewbuild
mikenewbuild

Reputation: 148

If you only want it to output once on the first iteration of the loop and assuming you're looping over variants (it might help to see all of your loop) you can use forloop.first


{% if forloop.first %}
  {{ item.variant.options[forloop.index0] }} {{ item.product.price[forloop.index0] }}
{% endif %}

Or you might find that you can just dispense with the loop and do

{{ item.variant.options.first }} {{ item.product.price.first }}

Upvotes: 1

Related Questions