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 do I display the total number of items on the cart page?

How do I display the total number of items on the cart page?

Mamdouh_USD
Excursionist
38 0 6

Hello all,

 

I'm using my phone and I want to display the total number of items placed on the cart page in a certain area as shown in the picture below. I also want it to be shown on desktop.

 

My store URL: https://u7yeji-na.myshopify.com/cart

 

IMG_D406E607D30C-1.jpeg

Replies 2 (2)

deckhand
Shopify Partner
1 0 0

Hey there!

If you are comfortable working with liquid in your theme, you could use the cart.item_count (link) field on the cart object. 

You have {{ cart.item_count }} cartons of water

If you want specifically a subset for just one type of product, you could loop through your cart items to find the number you want, save it to a variable, and then display that.

{% assign carton_count = 0 %}

{% for item in cart.items %}
  {% if item.product.type == "Water" %}
    {% assign carton_count = carton_count | plus: item.quantity %}
  {% endif %}
{% endfor %}

You have {{ carton_count }} cartons of water.

 

 

Mamdouh_USD
Excursionist
38 0 6

Hi @deckhand,

 

Can you walk me through step by step with pics on how I get this done and where should I place the codes exactly? Thank you in advance.