All guides › Cart page upsell
Shopify cart page upsell without an app (that hides what's already in the cart)
Disclosure: I build No-App Sections; this guide was written with AI assistance. The code on this page was written for this guide. It passes Shopify's Theme Check inside Dawn 16.0.0 and automated tests in headless Chrome, run against Dawn's own cart and variant events with mocked store data. It hasn't been run on a live store yet, so try it on a duplicate theme first.
The cart page is where an upsell is most likely to be ignored, or to embarrass you by suggesting the exact product the shopper just added. This guide builds a proper theme section for Dawn's cart template. You choose the products in the theme editor, and the section quietly drops anything that's sold out or already in the cart. Because Dawn updates the cart page without reloading, the section also refreshes itself whenever the cart changes.
Why a real section, not a Custom Liquid box
A Custom Liquid section can't have its own settings. To let you pick products with Shopify's product picker, and change the heading without touching code, the upsell needs a {% schema %}. That means creating a section file in the code editor once. After that, everything is done in the theme editor.
The section file
{%- comment -%}
sections/cart-upsell.liquid: hand-picked upsells for the cart page that skip anything already in the cart.
{%- endcomment -%}
{%- liquid
assign in_cart_ids = cart.items | map: 'product_id'
assign shown = 0
-%}
<div class="cart-upsell page-width" id="cart-upsell-{{ section.id }}" data-section="{{ section.id }}">
{%- capture cards -%}
{%- for pick in section.settings.products -%}
{%- if shown >= section.settings.max -%}{%- break -%}{%- endif -%}
{%- if pick.available == false or in_cart_ids contains pick.id -%}{%- continue -%}{%- endif -%}
{%- assign v = pick.selected_or_first_available_variant -%}
<li class="cart-upsell__card">
<a href="{{ pick.url }}" class="cart-upsell__link">
{%- if pick.featured_image -%}
{{ pick.featured_image | image_url: width: 300 | image_tag: loading: 'lazy', class: 'cart-upsell__img' }}
{%- endif -%}
<span class="cart-upsell__name">{{ pick.title | escape }}</span>
</a>
<span class="cart-upsell__price">{{ v.price | money }}</span>
<form method="post" action="{{ routes.cart_add_url }}">
<input type="hidden" name="id" value="{{ v.id }}">
<input type="hidden" name="quantity" value="1">
<button type="submit" class="button button--secondary">Add to cart</button>
</form>
</li>
{%- assign shown = shown | plus: 1 -%}
{%- endfor -%}
{%- endcapture -%}
{%- if shown > 0 and cart.item_count > 0 -%}
<h2 class="cart-upsell__heading">{{ section.settings.heading | escape }}</h2>
<ul class="cart-upsell__grid" role="list">{{ cards }}</ul>
{%- endif -%}
</div>
<style>
.cart-upsell { margin-bottom: 3rem; }
.cart-upsell__grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 1.5rem; grid-template-columns: repeat(2, 1fr); }
@media screen and (min-width: 750px) { .cart-upsell__grid { grid-template-columns: repeat(4, 1fr); } }
.cart-upsell__card { display: flex; flex-direction: column; gap: 0.6rem; }
.cart-upsell__link { color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 0.6rem; }
.cart-upsell__img { width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; }
.cart-upsell .button { width: 100%; min-width: 0; }
</style>
<script>
(function () {
var root = document.getElementById('cart-upsell-{{ section.id }}');
if (!root) return;
function init() {
if (typeof subscribe !== 'function' || typeof PUB_SUB_EVENTS === 'undefined') return;
if (window.cartUpsellOff) window.cartUpsellOff();
/* Dawn updates the cart items without a reload; re-render this section so it never */
/* offers something the shopper just added (or hides something they just removed). */
window.cartUpsellOff = subscribe(PUB_SUB_EVENTS.cartUpdate, function () {
var current = document.getElementById('cart-upsell-{{ section.id }}');
if (!current) return;
fetch(window.location.pathname + '?section_id=' + current.dataset.section)
.then(function (r) { return r.text(); })
.then(function (html) {
var fresh = new DOMParser().parseFromString(html, 'text/html').getElementById(current.id);
if (fresh) current.innerHTML = fresh.innerHTML;
})
.catch(function () {});
});
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
else init();
})();
</script>
{% schema %}
{
"name": "Cart upsell",
"enabled_on": { "templates": ["cart"] },
"settings": [
{ "type": "text", "id": "heading", "label": "Heading", "default": "You might also like" },
{ "type": "product_list", "id": "products", "label": "Products to suggest", "limit": 8 },
{ "type": "range", "id": "max", "label": "Show at most", "min": 1, "max": 4, "step": 1, "default": 4 }
],
"presets": [{ "name": "Cart upsell" }]
}
{% endschema %}
How it stays correct
- Skipping in-cart products:
cart.items | map: 'product_id'gives the IDs of products in the cart, and the loopcontinues past any pick in that list. It compares products, not variants, so a shopper with the blue T-shirt isn't offered the red one. - Refreshing: when the shopper changes a quantity or removes a line, Dawn's
cart.jspublishesPUB_SUB_EVENTS.cartUpdate. The section then asks Shopify to render just itself (?section_id=, the Section Rendering API) and swaps its contents. Remove the only jumper and the jumper becomes eligible again. - Empty cart: it renders nothing. Dawn shows its own empty-cart message there.
- Enabled on the cart template only (
"enabled_on"), so it doesn't clutter the "Add section" list elsewhere.
Install it
- Duplicate your theme. In Online Store → Themes, duplicate your theme. Do the next steps on the copy.
- Create the section file. Click … → Edit code. In the sections folder, click Add a new section, name it
cart-upsell, replace everything in it with the code above, and click Save. - Add it to the cart page. Go back and click Customize. Choose Cart from the page selector, click Add section → Cart upsell, and drag it below the cart items.
- Pick products. Choose up to 8 products in Products to suggest, set Show at most (1 to 4) and the heading. Click Save.
What it deliberately doesn't do
- Add to cart without a reload. The buttons are plain Shopify forms: the product is added and the cart page reloads with it. On the cart page that's the expected behaviour and works in every theme.
- The cart drawer. This is for the cart page. If Theme settings → Cart → Cart type is Drawer, most shoppers only see the page if they click through. For the product page, see the add-another-product button.
- Automatic recommendations. It shows only what you pick. For products picked per product, see the complementary products guide.
Other themes
The Liquid and the schema are standard Online Store 2.0, so the section can be added to any OS 2.0 theme's cart template. page-width and button button--secondary are Dawn class names: replace them with your theme's container and button classes. The live refresh needs Dawn's subscribe. In other themes the list updates on the next page load.
Testing checklist
- Pick 5 products, show at most 4: four cards appear.
- Add one of them: it disappears from the list and the fifth takes its place.
- Remove it with the bin icon: it comes back without a reload.
- Mark a pick as sold out: it's skipped.
- Empty the cart: the section disappears.
Want an upsell row on any page in a couple of minutes?
The Upsell block is a ready-made section: up to 4 products you pick in the theme editor, with images and add-to-cart buttons, and sold-out products labelled. It can go on product pages, the cart page or the home page. To be clear, it doesn't hide products already in the cart, which is the extra that the code above adds. £12 one-off, for one store, tested on Dawn and Horizon. Other Online Store 2.0 themes may need small style tweaks.
FAQ
Why does the page reload when I click "Add to cart" here?
The buttons are plain cart forms, so they work everywhere. Shopify adds the product and returns to the cart page, which then shows the updated cart and upsell list.
Can I show it in the cart drawer instead?
Not as it is. The drawer is a snippet, not a template you can add sections to. That would mean editing snippets/cart-drawer.liquid, which this guide doesn't cover.
Why "product" and not "variant" when checking the cart?
Offering a second colour of something already in the cart is rarely what you want. Compare item.variant_id instead if it is.
Does the refresh cost extra requests?
One small request each time the cart changes on the cart page. Nothing on page load.
Will it work with Shopify Markets?
Prices use the money filter, so they show in the shopper's currency, like the rest of your cart page.