Cart permalinks: links that fill the cart

Build a Shopify link that adds products to the cart and opens checkout: /cart/variant-id:quantity, with discount codes, email and the cart page.

Format
/cart/<variant ID>:<quantity>,…
Plan
Every plan
Needs
Numeric variant IDs
Status
Legacy, still supported; successor: Cart and Checkout Permalinks (/buy/)
Last checked

In short

A Shopify cart permalink is a URL like your-store.com/cart/12345678901234:1 that fills the cart with that variant and quantity and opens checkout. Add more items with commas, a discount code with ?discount=CODE, and ?storefront=true to land on the cart page instead. It works on every plan without an app; selling plans are not supported.

How to use it

  1. Find the variant ID: open the product in the admin, click the variant, and copy the number at the end of the URL.
  2. Build the link: https://your-store.com/cart/<variant ID>:<quantity>. Separate several items with commas.
  3. Add options as query parameters: discount=CODE, storefront=true for the cart page, checkout[email] to pre-fill the email.
  4. Open the link in a private window to check the cart before you share it.

Code

cart-link-button.liquid
{%- comment -%}
  A "Buy now" link for the product's selected variant, e.g. on a landing page.
  Use where `product` is available. routes.cart_url keeps the market's
  language path (/fr/cart), which cart permalinks support.
{%- endcomment -%}
{%- assign variant = product.selected_or_first_available_variant -%}
<a href="{{ routes.cart_url }}/{{ variant.id }}:1" class="button">Buy now</a>
links.txt
# One item: variant ID 12345678901234, quantity 1, straight to checkout
https://your-store.com/cart/12345678901234:1

# Two items, with a discount code applied
https://your-store.com/cart/12345678901234:1,12345678909876:2?discount=WELCOME10

# Fill the cart and open the cart page instead of checkout
https://your-store.com/cart/12345678901234:1?storefront=true

# Pre-fill the email and the shipping country at checkout
https://your-store.com/cart/12345678901234:1?checkout[email]=name@example.com&checkout[shipping_address][country]=Turkey

Written by Lintel. MIT license: free to use in your own store and in client work.

Limits and edge cases

  • The link replaces what is already in the cart.
  • Products on a subscription (selling plan) can’t be added this way.
  • Discount codes that contain a comma can’t be passed in the discount parameter.
  • Links don’t get past a storefront password.
  • Shopify now calls these links legacy and adds new features only to Cart and Checkout Permalinks (/buy/ links from the store’s UCP profile). The /cart/ format keeps working and is the one that supports line item properties and cart notes.

Questions

How do I make a Shopify link that adds a product to the cart?
Use your-store.com/cart/<variant ID>:<quantity>. It fills the cart with that variant and opens checkout; add ?storefront=true to open the cart page instead.
Can a cart link apply a discount code?
Yes: add ?discount=CODE, or several codes separated by commas, to the end of the link.
Where do I find the variant ID?
In the admin, open the product, click the variant; the number at the end of the page URL is the ID. On the storefront, /products/<handle>.js lists every variant with its id.
Do cart permalinks work with Shopify Markets?
Yes. Put the market’s language path before /cart, such as /fr/cart/12345678901234:1, and the cart and checkout open in that language.
  • Checked on a Shopify store on the date shown. Shopify changes its admin often; if a step looks different, the idea usually still works.
  • Examples use placeholder IDs and your-store.myshopify.com. Replace them with your own.
  • MIT license for the code snippets.

Need this built, tested and maintained for your store? See Shopify development.

Have something to build? Let’s talk it through.

Taking a limited number of projects at a time. Every brief is read by an engineer, not a salesperson.

Gencer KarakayaShopify Engineer

An engineer reads your brief, and we reply by email.