Increase AOV with multi-product add-to-cart permalinks for your Shopify store

How to add multple items to a cart with one permalink

By Rob Johnson

Wed Apr 27 2022

Running on Shopify and want a quick way to increase AOV?

Here are two permalink schemes that will allow you add mutliple variants and quantites to a cart.

You can use these custom permalinks anywhere. Custom theme templates, emails, social posts and so forth. You can dynamically create a bundle of products that get added to the cart all at once with no additional setup.

There are two URL schemes.

Add order lines

Add a product to the cart or, if the product already exists in the cart, increment the quantity of the product on the cart order line.

/cart/add?items[][id]=123&items[][quantity]=1&items[][id]=123&items[][quantity]=3

The numbers 123 and 456 represent Shopify variant ID's which can be found in the Shopify Admin URL when viewing the variant edit page.

See the Shopify URL path below.

/admin/products/11111/variants/88888

In the above example, 11111 is the product ID and 88888 is the variant ID.

Update order lines

Update quantity for specific variants in the cart or, if the product already exists in the cart, update the quantity for that order line.

/cart/update?updates[12345678910]=10&updates[12345678911]=2

In the above example, [12345678910]=10 represents the variant id 12345678910 and the quantity 10.

Limitation: If you already have a quantity of 10 for a given variant, the update method override the current quantity in the cart, with the quantity specified in the URL.

A quick overview of Products vs Variants vs SKU vs Order Lines

Both of these schemes rely on variant ID's. Variants are children of Products and have a "one-to-many" relationship. One product, to many variants.

For example a product called, "Super Cool T-Shirt" will can have many variants. These variant options can be color and size.

A variant represents a single item or SKU (Stock Keeping Unit) and can be dislayed as Super Cool T-Shirt - Gray L to the customer, Variant ID to the ecommerce system and SKU as a business key (accounting, business intelligence etc).

We want to determine exactly what should be added to the cart, so we use Shopify's variant ID which is a Shopify system key.

There is a 1:1 relationship between a variant and a SKU in most ecommerce setups. You can have what is called a KIT SKU, which is a parent SKU that has many children SKUS.

Order lines have their own system keys called order_line_key or something to that effect. Because each order line can be unique due to taxes, discounts and such, they are recorded in an order_line table and are children to the order_header table which stores all of the summary information for an order. Usually each order_line has an order_id which can be used to join to the order_header table.

Shopify now have official documentation on Creating Cart Permalinks. It's also recommended that this approach replace Shopify's "Buy Button" feature.

Adding a subscription with a selling plan

If you're selling subscriptions on Shopify, you'll need to pass in the selling plan id associated with the variant also.

/cart/add?items[][id]=123456789&items[][quantity]=1&items[][selling_plan]=555

You can also add &return_to=/checkout to send customers straight to the checkout.

If you need to clear the cart, you can hit the endpoint /cart/clear? instead with a return_to= param structured in the following way:

/cart/clear?return_to=/cart/add?items[][id]=123456789%26items[][quantity]=1%26items[][selling_plan]=555%26return_to=/checkout

AJAX API

You can also pass a json object through to the the cart page via /cart/add.js.

This will allow you to increment quantity also.

fetch('/cart/add.js', {
method: "post",
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
items: [
{
id: 123456789,
quantity: 5
},
{
id: 987654321,
quantity: 3
}
]
})
})

# commerce 9 # seo 4 # tools 5 # sql 3 # javascript 10 # projects 4 # css 2 # git 2 # php 3 # analytics 4 # monitoring 2 # api 3 # shopify 4 # python 2 # aws 2