I’ve noticed in the Shopify API documentation that the name and value associated with a line item property appear to be accessible with the objects line_item.properties.first and line_item.properties.last.
{% for property in line_item.properties %}
- {{ property.first }}: {{ property.last }}
{% endfor %}
I have assumed that it should be possible to write a for loop for the cart.liquid template that accesses these same objects, using them inside a conditional that would allow certain cart attribute input fields to be added to the cart page only if the customer has added a particular item with a particular line item property value.
This is what my attempt at doing this has looked like:
{% for attr in cart.items %}
{% if attr.properties.first == 'Name' and attr.properties.last == 'Value' %}
{% endif %}
{% endfor %}
This is not working in testing when the name and value match up with what is desired for the conditional. Considering the lack of documentation on doing something like this, I’m now thinking that I’m misunderstanding something important about liquid and the Shopify API. Is it possible to write a for loop that can accomplish what I am looking for?