We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

How can I correctly use the line_item.quantity if statement in Shopify?

Solved

How can I correctly use the line_item.quantity if statement in Shopify?

dolby_edmos
Visitor
3 1 1

Hello, I can't get a grip on the line_item object. I'm trying to to something like this in the cart before checkout:

 

{%- for collection in item.product.collections -%}

{%- if line_item.sku == "12345" and line_item.quantity > 1  -%}

<p>something...</p>

{%- endif -%}

{%- endfor -%}

 

I'm adding the code into main-cart-items.liquid (Dawn 2.0). 

 

Has anyone an idea how to solve this?

 

Greetings,

Eduard

 

P.S. I can't link the shop (secrecy).

Accepted Solution (1)

dolby_edmos
Visitor
3 1 1

This is an accepted solution.

For everyone who has the same question at some point. Here is what I've found out so far:

 

In main-cart-items.liquid you're already in a for loop:

 

{%- for item in cart.items -%}
 
so, if you want to loop or get data out of this loop you need to address the objects with simply "item.[...]". To get a better understanding write this snippet at some point in your loop:
 
<script>console.log({{ item | json }});</script>
 
With the dev tool on your browser you'll be able to see all properties/attributes. 

View solution in original post

Replies 2 (2)

dolby_edmos
Visitor
3 1 1

This is an accepted solution.

For everyone who has the same question at some point. Here is what I've found out so far:

 

In main-cart-items.liquid you're already in a for loop:

 

{%- for item in cart.items -%}
 
so, if you want to loop or get data out of this loop you need to address the objects with simply "item.[...]". To get a better understanding write this snippet at some point in your loop:
 
<script>console.log({{ item | json }});</script>
 
With the dev tool on your browser you'll be able to see all properties/attributes. 
George_C
Trailblazer
166 2 150