A space to discuss online store customization, theme development, and Liquid templating.
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
Hi everyone. I'm currently use Dawn theme.
I have a bar in announcement-bar.liquid with a message, the message will update when something is added or removed from the cart.
I created this Javascript file
document.addEventListener('DOMContentLoaded', function () { console.log("Hi! I'm here!!!"); function reloadAnnouncementBanner() {
//myCodeHere }); } } document.addEventListener('cart.itemAdded', function (event) { console.log("ITEM ADDED"); reloadAnnouncementBanner(); }); document.addEventListener('cart.itemRemoved', function (event) { console.log("ITEM REMOVED"); reloadAnnouncementBanner(); }); });
From the log i can see the log in the document listner (the "Hi! I'm here" log), so i know i call the js file correctly, but there are no "ITEM ADDED" or "ITEM REMOVED" whenever i try to add or remove an item from the cart, so i think the listner on the cart doesn't work.
Maybe someone has faced the same issue and has some answer, it'll be very great!
Thank you very much
Solved! Go to the solution
This is an accepted solution.
Hello,
There must be another functions used for cart items event like add and remove. That's why your new script on the same event not working. Try to find the flow and add your code in the same function.
Find the function in theme files "product-form.js" or "cart.js"
Let me know.
This is an accepted solution.
Hello,
There must be another functions used for cart items event like add and remove. That's why your new script on the same event not working. Try to find the flow and add your code in the same function.
Find the function in theme files "product-form.js" or "cart.js"
Let me know.
Hi, sorry for the late reply.
I've found the remove function on the cart.js, and it's working, so really thank you.
On the adding function in product-form.js i'm facing some issues, since i cannot find something clear like the remove function. But i'll keep searching