# Custom code Changing theme code isn't covered by support. An update copies your code edits only when they don't clash with the new version (see [Update](page:update)), so keep a copy of what you changed. Before you edit code, **duplicate the theme** (**Online Store → Themes → … → Duplicate**) and work on the copy. For larger changes, hire a Shopify Partner: [shopify.com/partners/directory](https://www.shopify.com/partners/directory). For small styling changes, prefer the **Custom Liquid** section and block, or **Theme settings → Custom CSS**, which carry over to new versions. @image(media/guides/editor-theme-css.jpg "Theme settings → Custom CSS" "Editor · panel") ## For developers: JavaScript events The theme fires these events so apps and custom code can react without editing theme files. Listen with `document.addEventListener('cart:updated', (event) => { … })`. | Event | Fired on | When | `event.detail` | |---|---|---|---| | `cart:updated` | `document` | After any add, change or update through the theme, including the cart drawer, quick add and cart page | The cart object from Shopify's Cart API (`items`, `item_count`, `total_price` and more) | | `cart:error` | `document` | When adding to the cart fails, for example when stock runs out | `{ button, message }`: the add button and Shopify's error message | | `collection:updated` | `document` | After filtering, sorting, "Load more" or infinite scroll changes the products in a collection or search grid | `{ added }`: how many products were added or are now shown | | `overlay:open` | the drawer or dialog (bubbles) | When a drawer, quick view, search or other overlay opens | none | | `overlay:close` | the drawer or dialog (bubbles) | When it closes | none | | `fit-profile:changed` | `document` | When a shopper saves their result in the fit finder | The saved profile, for example `activity`, `support` and `summary` | | `variant:change` | `document` | When the shopper picks another variant on a product page, a featured product or in quick view (not for the variant the page opened with) | `{ variant, sectionId, productUrl }`: the variant (`id`, `price`, `available`, `sku`, `options` and more, or `null` for a combination that doesn't exist) | | `product:variant` | the product block (bubbles) | Each time a product block settles on a variant, including when it first loads | `{ variant }` | | `newsletter:subscribed` | the sign-up form (bubbles) | After a newsletter sign-up succeeds | none | | `endurance:ready` | `document` | Once the theme's script has run and `window.Endurance` (cart helpers below) is ready. Scripts loading later can check `window.Endurance?.ready` instead | `{ endurance }` | ### Cart helpers `window.Endurance.cart` uses the same requests as the theme, so the drawer, counters and rewards bar update for you: - `Endurance.cart.add([{ id: variantId, quantity: 1 }])` adds items and refreshes the cart. - `Endurance.cart.change(lineKey, quantity)` changes one line. Use `0` to remove it. - `Endurance.cart.refresh()` re-renders the cart after an app changed it some other way. If an app adds to the cart with its own request, call `Endurance.cart.refresh()` afterwards so the drawer and the cart count show the change. ## Custom CSS **Theme settings → Custom CSS** applies to the whole store, and each section has its own **Custom CSS** field at the bottom of its settings, which applies to that section only. Shopify limits how long these fields can be; for longer code, add a **Custom Liquid** section with a `