susan
susan

Reputation: 382

Display only certain Shopify line items

This is for a Shopify site. Is there a way to display only certain line item properties in the cart? I have several and it looks messy so only want to display a chosen two or three.

Upvotes: 2

Views: 2795

Answers (1)

Steph Sharp
Steph Sharp

Reputation: 11682

I am assuming you have set up your line item properties similar to how it suggests on the Shopify wiki (Line Item Properties).

You will have something like this in product.liquid:

<div>            
  <p><label for="property1">Property 1:</label></p>
  <p><input type="text" id="property1" name="properties[Property1]" /></p>
</div>

Then put this code in cart.liquid, beneath the cart item's title:

{% for p in item.properties %}
  {% if p.first == 'Property2' or p.first == 'Property5' %}
    {% unless p.last == blank %}
      {{ p.first }}:
      {% if p.last contains '/uploads/' %}
      <a class="lightbox" href="{{ p.last }}">{{ p.last | split: '/' | last }}</a>
      {% else %}
      {{ p.last }}
      {% endif %}
      <br />
    {% endunless %}
  {% endif %}
{% endfor %}

The code above is straight from the Line Item Properties article on the Shopify wiki (section 3.1 Displaying line item properties on the cart page). I've just added the if statement on the second line to only display the properties I want:

{% for p in item.properties %}
  {% if p.first == 'Property2' or p.first == 'Property5' %}
    ...
  {% endif %}
{% endfor %}

Or, if you want to display several properties in a row (e.g. the first 3 properties), you could do it like this (without the if statement):

{% for p in item.properties limit:3 %}
  ...
{% endfor %}

Upvotes: 5

Related Questions