Skip to content

Shopify Dude Fix

Shopify AJAX Cart Works in English but Breaks in Translated Markets? Stop Hardcoding Routes

Keep custom cart requests and theme links in the current storefront language and market context.

Quick answer: Use window.Shopify.routes.root for Ajax endpoints and Liquid routes for storefront links and forms. Do not construct every request from a hardcoded slash or a guessed language prefix.
On this page

Why this happens

Many older AJAX examples assume the storefront lives at the domain root. A translated or regional storefront can have a path prefix, and hardcoded URLs can send requests or navigation outside the intended context. A successful English test does not establish that localized requests are correct.

How to fix it

Search theme assets and snippets for literal cart/add.js, cart/change.js, cart.js, search and cart links. Build Ajax paths from the runtime root, preserving its trailing slash. Use routes.cart_url and routes.cart_add_url for Liquid links and forms. Preserve the current page context when requesting section HTML. Review app-generated requests separately rather than changing vendor code blindly.

Practical example

For a read-only cart check, use fetch(window.Shopify.routes.root + 'cart.js').then(r => { if (!r.ok) throw Error(r.status); return r.json(); }). For writes, use the same root with cart/add.js or cart/change.js and the appropriate POST body. In Liquid, a cart link can use {{ routes.cart_url }}. Run Theme Check to catch hardcoded Liquid routes.

Common misunderstanding: A locale-aware path is not a substitute for configuring Markets, publishing languages or validating catalog availability. It simply keeps requests aligned with the storefront context.
How to test this:

  1. Preview a duplicate theme in the default language and a published secondary language
  2. inspect request URLs in DevTools
  3. add, change and remove an item
  4. compare cart totals and translated section HTML
  5. test the cart link and checkout
  6. switch market and repeat
  7. check quick-add and app-powered drawers separately.