Core Issue:
A tutorial explains how to prevent Shopify product pages from redirecting to the cart after adding items, allowing customers to continue shopping. The solution involves adding custom code (ajaxify-cart snippet) to theme files.
Implementation Steps:
Add {% render 'ajaxify-cart' %} above closing </body> tag in theme.liquid
Create ajaxify-cart.liquid snippet with provided code
Theme-specific modifications required (especially for Debut theme)
Replace deprecated .size() method with .length
Common Problems Reported:
Cart counter not updating:
Solution involves changing cartCountSelector code and replacing ‘hidden-count’ class with ‘hide’ class
Some users need to add jQuery script tag
Still redirects to cart:
Often caused by missing steps or outdated theme versions
Updating to latest theme version sometimes resolves issues
This is an advanced tutorial and is not supported by Shopify. Knowledge of HTML, CSS, JavaScript, and Liquid is required. Consider hiring a Shopify Expert if you aren’t comfortable doing the steps in the tutorial.
When a customer adds a product to the cart, some Shopify themes will take them to the cart page. This customization lets customers stay on the product page after clicking the Add to cart button, so that they can continue shopping.
Note: Most free Shopify themes include a setting that lets customers stay on the product page when a product is added to the cart. You can enable this in the theme editor, in either the Cart page settings, or the Product page settings. In the theme preview, navigate to the cart page to access the Cart page settings, or navigate to the product page to access the Product page settings.
Edit your theme code
To edit your theme code:
From your Shopify admin, go to Online Store > Themes.
Find the theme you want to edit, and then click Actions > Edit code.
Caution: In the pasted code, replace all instances of .size() with .length. The .size() method is depreciated as of JQuery 1.8.
Click Save.
Debut
If you use Debut, then continue to the next steps:
In ajaxify-cart.liquid, find the opening <script> tag at the top of the file. On a new line right below the opening <script> tag, paste the following code:
window.onload = function() {
Find the closing </script> tag. On a new line right above the closing </script> tag, paste the following code:
Hi! Have there been any updates to this at all? I’m using the Debut theme and I’ve followed these instructions exactly and triple checked it all. I still get sent to the cart when adding a product.
@Ardi94 I was actually able to get this working last night but I ran into some other issues. When I remove the “defer” portion (as referenced in the comment in this post) from the theme.liquid file, my slideshow and dropdown navigation stop working. If I leave the “defer” portion, the add-to-cart functionality doesn’t work and I get redirected to the cart anyway.
I’m trying to sort this out and see if I can find another way to get this working!
Applied this fix as I was having the same issues. What’s happening now is that it’s still going to the cart but there’s like a 2 second pause before it goes to the cart. Any ideas?
I really wanted this to work for me because it is absolutely something I need for my shop. I followed it to a T.. but sadly it still takes me to the cart page instead of just adding to cart.
Hi, it works for me! Thank you. Is there any way to change the colour of the message that pops up after adding to cart? Part of it is now green and I would like to change it to all black.
If you’ve had the Debut theme longer than 6 months or so, there’s an updated version in the theme store. You can check it out there. Click through the theme like its an active store. If it’s doing the things you want your store to do, then customize it and get it the way you want it before publishing it. Took me about an hour to get it all set up and looking like our original Debut themed store. Once you have it the way you want it, click on publish and take it live. Keep in mind, if you have some apps running on your store, you may need to add a snippet of code, which the app should email you with instructions on how to do this when you take it live. Is really pretty simple if you have a little computer knowledge. We have about 6 apps running on our store and only one needed the snippet added.
For the Brooklyn theme, this worked by just creating the Ajaxify-cart.liquid snippet. Did not have to do the additional steps as has been listed for “Debut”. Will be testing and confirming if this works fine. The only place I have caught an issue is with Product Recommendations (within a single Product page, at the bottom), where the Add To Cart button is still opening the Cart Page.