How do I refresh the cart drawer after adding an item to cart via ajax? - ajaxify shopify

Shopify Partner
2 0 2

Let me know if this worked for you.

var o = ".ajaxcart"; // adjust it accordingly

var e = "#CartContainer"; // adjust it accordingly

document.dispatchEvent(new CustomEvent("updateCart" + o,{detail: e})),

2 0 0


Thank you for the help.

I have kept the given code and it works when I click on the add to cart button. The cart drawer opens with the new item and it doesn't close. The requirement is filled but I have another requirement of a external snippet that is implemented into the store. I actually added the above code in the external snippet which adds an item when clicked on the checkbox. Currently when clicked on the check box and click on the refresh whole page the new item is added (checkbox unchecked and whole page refreshed the item is removed) and the cart drawer is closed. But after keeping the given code in external snippet I wasn't able to add the item with a checkbox. I have posted a question with the external code. Can you please look at it and let me know what the variables should be adjusted accordingly. I appreciate your help very much. Thank you.

Shopify Partner
2 0 2

Hello Yuri, 

Its good to know solution helped you, I'll look at other problem too and try to find a solution. Meanwhile, if this solution helped you, mark it as solution, so that other community members can find it.

40 2 12

Hi Yuri, 

I am using the impulse theme as well and would like to add this feature to my cart drawer. 

I am unfortunately not good at javascript.

Would you maybe be kind enough to copy the part with the feature and where it should be placed, so I can add it to my javascript? 

Thank you in advance 

Best regards 

Maria Jensen