Join us March 21 for an AMA on planning your 2023 marketing budget with 2H Media co-owners, Matt and Aron

Cart - Use permalinks to pre-load the cart

TyW
Community Manager
Community Manager
418 40 1141


What is a cart permalink?

A cart permalink takes your customers directly to the first page of the checkout screen with items pre-loaded into their cart.

Have you ever wanted to link directly to the Shopify checkout screen with a specific cart already loaded with items? Have you ever wanted to put a "Buy it now" button in blogs and newsletters? Have you ever wanted to provide an easy reorder link to customers? Cart permalinks are the answer.

This is what a cart permalink looks like:

http://your-store.myshopify.com/cart/70881412:1,70881382:1

Where 70881412 is the product variant's unique ID and 1 is the quantity.

So the format of the url is:

http://yourstore.com/cart/#{variant_id}:#{quantity}(,...)


Appending cart and checkout parameters

You can pre-fill any of the checkout fields, simply by appending checkout query parameters in the cart permalink URL. When appending checkout query parameters, use the following URL format:

/cart/{variant_id}:{quantity}?checkout[email]=somebody@store.com&checkout[shipping_address][city]=thisismyhometown

where [email] represents any of the possible checkout fields in the form, and [shipping_address][city] shows how you can use nesting to populate child fields.

List of supported checkout parameters

You can pre-fill any of the following query parameters:

Checkout parameter Description
checkout[email] Email of the customer making the checkout.
checkout[shipping_address][first_name] Address [first_name].
checkout[shipping_address][last_name] Address [last_name].
checkout[shipping_address][address1] Address [address1].
checkout[shipping_address][address2] Address [address2].
checkout[shipping_address][city] Address [city].
checkout[shipping_address][zip] Address [zip].


Applying a discount

You can directly apply a discount to a cart permalink.

The following format applies the discount:

/cart/{variant_id}:{quantity}?discount=test

where test is the string value of a discount code.

Note: Notes, cart attributes, and tracking parameters can be added as query parameters as usual. If customer accounts are enabled on your website, and the user is not logged in, they will see the login page before reaching the checkout.

Adding a "Buy this" link to a blog post

  1. From your Shopify admin, go to Online Store > Blog Posts.
  2. On the Blog posts page, either add a new blog post or click on an existing blog post.
  3. In the Rich Text Editor, under the "Content" header, click the HTML button:

    preload01.jpg

  4. Add your link. It should look something like this:

    <p><a href="http://your-store.com/cart/70881412:1">Buy this item</a></p>
  5. Save your changes and test it out in your store.

Adding a "Reorder" link

You can add a "reorder" link right in your theme's customers/order.liquid template for each line item in the order.

 

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. Under the Templates folder, locate and click on customers/order.liquid to open it in the online code editor. Don't see the template? Create one by clicking the Add a new template link.
  4. In the online code editor, paste the following piece of code where you would like your link to appear:

    <a href="/cart/{{ line_item.variant_id }}:{{ line_item.quantity }}">Reorder this</a>

     

  5. Click Save to confirm your changes.

Conversion tracking

Wish to add some tracking info to the URL, which will then show up on the order details page in your admin, when orders come in?

Use a cart note:

/cart/70881412:1,70881382:1?note=came-from-newsletter-2013-02-14


Or use a cart attribute (you can have several of those):

/cart/70881412:1,70881382:1?attributes[where-from]=came-from-newsletter-2013-02-14&attributes[some-other-key]=some-value


The cart note and cart attributes are shown on the order details page under Order Note.

Or use the 'ref' parameter:

/cart/70881412:1,70881382:1?ref=came-from-newsletter-2013-02-14


The ref value is shown as a referral code in the Conversion summary section on the order details page. Click View conversion details and then click View full sessions to view the session details page:

 

preload02.png


Sales attribution

To attribute an order to a sales channel or app, you can add an additional parameter to the permalink. You can view sales attributions in the Sales by Channel report, which shows the name of the channel or app that the customer used to place their order. Sales attributions also appear on the sidebar in your Shopify Home. You can specify a storefront access token in the cart permalink as shown in the following example:

/cart/70881412:1,70881382:1?access_token=#{access_token}
 

Can I let the customer edit quantities?

You can't. Quantities cannot be edited when the customer follows a cart permalink.

Finding a variant ID

Click here to learn how to find a variant ID from within your Shopify admin.

 

TyW | Online Community Manager @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Replies 112 (112)
jhcao23
Excursionist
31 1 15

Hi @TyW will shopify publish any official docs about the cart permalink?

tschach
New Member
3 0 4

Thanks for this...this is partly what I'll need. However, we are running Shopify in headless mode. This means we don't have a store on Shopify all we use are buy-buttons.

 

So when I use the buy-button builder I can check that it directly forwards to the checkout-page. Do something like:

 

https://mydomain.myshopify.com/27337588471/checkouts/0739e8c6084f8a2857ef841954c2474c

 

Which then includes the product I selected before via pressing the button. This forward to the checkout page will be initiated when you set "buttonDestination": "checkout" in your setup.

 

When I use the instructions on this page, it tries to open the Shopify webstore pages which we don't have and which is not exactly what I need. Is there any way to add a product via a link and then go to the checkout page?

 

Thanks, Carsten

 

EbonyMaw
New Member
2 0 1

@TyW  Thanks for the article.

This is something that would work really well for our unique situation because we want to introduce an additional step before checkout. The one checkout attribute that seems to be missing from here is the State/Province. How can we set that using permalinks?

Ginko
Shopify Partner
20 0 12

Hello,

 

Thank you for the article. However, as mentioned by the previous poster, we are not able to set the Country/Region and Province fields.

 

How can we set this using the permalinks?

 

Thank you!

 

Sebastian

Ginko
Shopify Partner
20 0 12

It seems to work using these parameters 

&checkout[shipping_address][country]=US&checkout[shipping_address][province]=NY
 
Make sure the use the two-letter codes!
EbonyMaw
New Member
2 0 1

Thanks Sebastian! That works!

brendonwbrown
Shopify Partner
13 1 16

This is a fantastic guide, thank you. 

Unfortunately when I attempt to follow it I am redirected to checkout immediately with that single item.

I am looking to simply add the item to the cart.

danstoj
Excursionist
17 0 17

Can you do a discount and conversion tracking in the one link?

Yahya53
New Member
1 0 3

@brendonwbrown Did you find a way to add the item to the cart?

brendonwbrown
Shopify Partner
13 1 16

Indeed I have!

Get your variant ID as in the tutorial above and format your url as below:

https://domain.com/cart/add?id[]=variantid

 

You can add multiple products 

https://domain.com/cart/add?id[]=variantid&id[]=variantid&id[]=variantid

 

mjniuz
New Member
1 0 1

How to add custom currency for checkout url?

uphillman12
Tourist
5 0 4

@TyW Thanks for the helpful post. It looks like your original post uses the term "cart" in many places where it should say "checkout".

 

 

Using a permalink in the way you state:

/cart/{variant_id}:{quantity}

does not load anything into the cart cookie for Shopify as a user  would think by reading "pre-load cart."

 

Rather using this permalink initiates a new checkout with the items in the URL.

 

Consider reviewing and updating your original post to state that "Use permalinks to pre-load the checkout"

 

If Shopify added a feature to add the checkout permalink's items to the cart cookie then your post would be closer to accurate. Here's more on that issue:

https://community.shopify.com/c/Shopify-APIs-SDKs/Possible-permalinks-bug-when-pre-loading-carts/m-p...

ngoenka
Excursionist
33 0 11

I've been able to add multiple items w. differing quantities to cart by using the below:

 

https://groupbazaar.in/cart/update?updates[variant_id]=qty&updates[variant_id]=qty&updates[variant_i...

replace variant_id & qty

 

However, the problem is that it adds these items in addition to the already existing items in the user's cart.

 

How do I construct the URL so that shopify clears all the items in the user's cart & then add the selected items. I intend to share this URL as a Whatsapp message/share & hence, needs to very simple for users.

 

Any help would be much appreciated!

bradlau
Tourist
5 0 3

@danstoj Did you find a way to do a discount and conversion tracking in the one link?

 

The article says "Notes, cart attributes, and tracking parameters can be added as query parameters as usual," but it's not working for me. 

 

For example, this adds the products & quantities to checkout, but doesn't apply the discount:

/cart/{variant_id}:{quantity},{variant_id}:{quantity}?discount=discountName?ref=email@domain.com

 

If I remove the ?ref=email@domain.com it does apply the discount. Anyone know what I'm doing wrong?

JAS_Technology
Shopify Expert
83 0 48

Has anybody noticed that when you use a checkout page permalink the "cart" link at the top is still active? When clicked it just goes to a blank cart. I feel like this is a checkout bug right? 

 

Image 2020-05-29 at 2.41.51 PM.png

Happy to hear about your crazy ideas.
ngoenka
Excursionist
33 0 11

I have a similar question. I'm able to add multiple items to cart but when I append ?ref= , I dont have get this reference on order conversion.

 

A sample URL that I'm using:

https://groupbazaar.in/cart/update?updates[33826291384458]=1&updates[32056616124554]=2?ref=whatsappS...

 

Any thoughts?

uphillman12
Tourist
5 0 4

@bradlau and @ngoenka You should be using a "&" instead of another "?" in your parameters. 

 

For example,

?key1=value1&key2=value2&key3=value3

 

https://en.wikipedia.org/wiki/Query_string

uphillman12
Tourist
5 0 4

@JAS_Technology Semantics if we call it a bug or an oversight. Either way, something Shopify should fix this.

 

If you're curious why the checkout permalink described in the original post causes this read more here.

https://community.shopify.com/c/Shopify-APIs-SDKs/Possible-permalinks-bug-when-pre-loading-carts/m-p...

 

If the original post went to the cart as the author suggested it would load Shopify's cart, going straight to checkout seems to clear the cookie and ignore the new contents entirely.  It's likely Shopify never considered a user starting a checkout and not completing it in one direction. Have you tried just getting a 100% checkout conversion rate? 😄 

ngoenka
Excursionist
33 0 11

Thanks but it doesnt help me put a ref in for conversion tracking. I even tried putting a &tags=<sometext> but this doesnt add tags to the order which is generated when customers go through this link.

 

I've basically created a whatsapp share message for users to send a product to their friends. The friend can simply click the message, add the products to cart, review & checkout. I want conversion tracking on this so that I can understand the efficacy of this flow.

 

any suggestions?