Count all products quantity in checkout

Solved
Highlighted
Tourist
7 0 0

Hi. I am trying to count all the products quantity/variants that are visible in the checkout page.

 

Below, is that code that I currently have:

{% assign itemCount = 0 %}

{% for item in checkout.line_items %}
  {% assign itemCount = itemCount | plus: 1 %}
{% endfor %}

{{ itemCount }}

 

The code counts all the products, but if one of the products has quantity more than 1, it will still count as 1, not 2.

Here is an example, where the count should be equal with 4:

Screenshot 2020-09-15 at 16.18.39.png

 

Any help is appreciated!

Thank you

0 Likes
Highlighted

Hello,

Firstly are you working on a Shopify Plus store? Only with the Plus plan you can edit the checkout.

Kind regards,
Diego

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Hire me! Recommended by 25+ customers on Facebook. Click here to read their reviews.
◦ Contact me at: diego.boarutto.fortes@gmail.com
0 Likes
Highlighted
Tourist
7 0 0

Hi, yep. the screenshot you see is from the store checkout

0 Likes
Highlighted
Tourist
7 0 0

Hi Diego, any chance you could help with this?

0 Likes
Highlighted
Shopify Partner
1441 194 501

This is an accepted solution.

Yo @webg, just got your DM. You need to use the current line_item.quantity and add it to the count every loop, but first you need to multiply it by 1 with a liquid math filter since it's initially a string and you cannot add it:

    {% assign total_item_count = 0 %}
    {% for item in checkout.line_items %}
      {% assign item_quantity = item.quantity | times: 1 %}
      {% assign total_item_count = total_item_count | plus: item_quantity %}
    {% endfor %}
    {{ total_item_count }}

 

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
1 Like
Highlighted
Tourist
7 0 0

Yo Anthony.

 

yess! this solution works. thank you so much. you rock

0 Likes