Assistance needed: Prevent redirect to cart page after "Add to Cart" on cokodive.com

Hi there,

I recently had my website (cokodive.com) renewed by a Shopify customization agency. I would like to change the ‘Add to Cart’ behavior so that customers stay on the current product page instead of being automatically redirected to the cart page.

I’ve checked the theme settings, but there is no option to toggle this off. I suspect I need to edit the code. I searched for assets/product-form.js as suggested in some guides, but it doesn’t exist in my theme. However, I do see a product-form.liquid file.

Could you please guide me on how to enable the AJAX (stay-on-page) cart functionality for my theme?

Thank you!

Hi @cokodive, the AJAX cart is usually referenced as Cart Drawer. Depending on the theme the agency you worked with used as a starting point this feature might already be present behind a setting. For example Dawn is a common starting point and in the case of that theme the default behavior is redirecting to the cart page, but it does support a cart drawer by going to the Theme Editor > Settings > Cart as you can see in this image.

If your theme is entirely custom-made you could either ask the agency who built it about this feature. They could either point you out to where this is enabled or let you know if this is something they can implement.

In any case, if your theme definitely doesn’t have this feature and you need support adding it you can send me a Direct Message and I’d be happy to take a look.

Your theme is Turbo.
Check the theme manual first:
https://help.outofthesandbox.com/hc/en-us/articles/360034833013-Turbo-cart-types-and-settings

I doubt agency has removed this setting.
The JS code is intact in assets/app.js (search for theme_settings.cart_action), so should be a matter of configuration.

Hi,

Hope this will help

The redirect happens because the product form submits normally

Here are some steps to enable “stay on page” Add to Cart

  • Check if AJAX is already partially implemented
  • Locate the product form
  • Add a JavaScript listener

Example

document.addEventListener('submit', function (e) {
  const form = e.target;

  if (form.matches('.product-form')) {
    e.preventDefault();

    fetch('/cart/add.js', {
      method: 'POST',
      body: new FormData(form),
      headers: {
        'Accept': 'application/json'
      }
    })
    .then(response => response.json())
    .then(() => {
      // Optional: update cart count or show message
      document.dispatchEvent(new CustomEvent('cart:updated'));
    })
    .catch(error => {
      console.error('Add to cart error:', error);
    });
  }
});

  • Check for hardcoded redirects added by agency built themes

Where would I paste this code?

The code above is just an example, and at best, it would do nothing in your theme.

Your theme already has Javascript code for this, you just need to enable it in settings.

However – there are some apps which require your cart to be Page type.

And if changing theme setting still does not work as you want it is very likely that some apps you’ve installed, intercept the “Add-to-cart” button click and do something other than what theme code is supposed to do.

In your case, I believe it’s the Zipify upsell app – check its configuration.