All Collections
Advanced Topics
Abandoned checkouts
How to build a prefilled discounted cart
How to build a prefilled discounted cart

Learn how to load a cart page that contains specific products, optionally with a Discount Ninja promotion applied

Bart Coppens avatar
Written by Bart Coppens
Updated over a week ago

Not sure how to edit your theme? Read this article first.


  • Open your theme

  • Click "Add a new template":

  • Select the template type "cart" and provide a name. In this example, we're using prefill. You can use a different name if you prefer.

  • Add the following content to the newly created template:

{%- layout none -%}

<!doctype html>
<html class="no-js" lang="{{ shop.locale }}">
{% render 'limoniapps-discountninja-header' %}
<script type="text/javascript">
document.addEventListener("limoniapps:discountninja:promotions:loaded",(function(){!function(){if("undefined"!=typeof discountNinja)try{for(var t=discountNinja.QueryParameter.Get("redirecturl"),n=decodeURIComponent(discountNinja.QueryParameter.Get("variants")).split(","),i=[],e=0;e<n.length;e++){var r=n[e].split("x");i.push({variant_id:r[0],quantity:r[1]})}discountNinja.Cart.Shopify.ClearCart().then((function(){return discountNinja.Cart.Shopify.AddToCartMultipleLines(i)})).then((function(){location.href=t||"/cart"}))}catch(t){discountNinja.Logging.LogError("RedirectWithPrefilledCart",t)}}()}));
{% include 'limoniapps-discountninja-body' %}
  • Click "Save"


You can now send your customers to a prefilled cart using a URL that has the following format:

This URL has the following required components:

  • replace this with the domain of your shop

  • /cart?view=: this part is mandatory

  • prefill: this is the name of the template; if you selected a different template name use it here

  • &variants=: this part is mandatory and requires a comma-separated list of the variant id of the product variants you want to add to the cart; for each variant you'll need to specify the quantity. Example: to add 2 of variant 1234567 and 1 of variant 2345678 use &variants=1234567x2,2345678x1

Additionally, you can add a token to the URL to trigger a Discount Ninja promotion that has a shareable link. If the trigger of your promotion is ABCDE then the link becomes:

Finally, you can define which page should be loaded once the cart is prefilled using a redirecturl parameter. By default the link will send customers to the cart page. If you want customers to land on the collections page instead you could use:


This approach:

  • clears the cart first

  • then adds the specified variants

This ensures the content of the cart will always be as defined in the URL, independent of what a customer had already added to the cart before.

Did this answer your question?