FROM CACHE - en_header

Cart information and events with script-tag?

New Member
3 0 0



A script-tag was added to the store.


From within this JavaScript script, how do I:

1. How do I tell how many items in the cart?

2. How do I tell when an item has been added to the cart (event)?


What options do I have in order to interact with the cart?

Looking for a client-side only solution.


Thank you.

Replies 5 (5)
Shopify Partner
11 0 3


For cart item count you can use

{{ cart.item_count }

You can call cart object anywhere in theme code files.

And for add to cart event you need to create it by own. 

You can create javascript click event.




New Member
3 0 0

Looking for a client side only solution. A theme is server side..


You can create javascript click event

Into which event do I hook?

Shopify Partner
1873 184 868

Yo, depends on your theme or if you're developing an app, then on the merchants theme.

Some themes add to cart via a form POST. Others use the Ajax API. Form submission can be easilly intercepted. For the Ajax API I suggest you play around with the sandbox and dig in to your theme's javascript to understand how it works.

Either way is possible, but there is no event you can hook in to as most if not all jQuery based themes I know of from Shopify don't work that way (i.e. don't use something like a global event bus or document bound events). So you'll have to wire this up yourself.

Best wishes!

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
New Member
3 0 0

Thank you Karl.

Shopify Partner
5 0 0