How to Add several Discount codes and products - ID not working - Perma Links

How to Add several Discount codes and products - ID not working - Perma Links

dr_max_owl
Visitor
3 0 2

How to Create a Shopify Permalink for Adding Multiple Products to Cart with Discounts (and Show the Cart Page Instead of Going Straight to Checkout)

 

If you’re trying to create a Shopify permalink to add multiple products to the cart, apply discount codes, and show the cart page instead of going straight to checkout, this guide is for you. I spent hours figuring this out, and neither Shopify Support nor existing community posts had the solution. Here’s what worked for me.

 

The Solution:

1.Show the Cart Page:

To display the cart page (not the checkout), you need to append ?storefront=true to the link.

2.Use Variant IDs, Not Product IDs:

Shopify permalinks require Variant IDs, even for products without variants. If you try to use a Product ID, it won’t work.

 

How to find the Variant ID:

- Open the product page in your store.

- Right-click and select Inspect (or “View Page Source”).

- Use CTRL+F (Windows) or CMD+F (Mac) and search for variant.

- Look for the Variant ID, which is a long numeric string (e.g., 12345678901234).

 

3.Apply Multiple Discount Codes:

While Shopify officially only supports one discount code per link, I found that adding multiple codes separated by commas does work in the cart permalink. For example:

&discount=CODE1,CODE2.

 

Example Permalink:

 

Here’s a working example with two products and two discount codes:

https://your-shopify-store.com/cart/12345678901234:1,98765432109876:1?storefront=true&discount=DISCOUNT1,DISCOUNT2

Replace:

12345678901234 and 98765432109876 with your Variant IDs.

- DISCOUNT1 and DISCOUNT2 with your discount codes.

 

Notes:

- If multiple discounts don’t work for you, try apps like Multi Discount Rocket. But it should work none the less with 2 codes

- Make sure all products and discounts are active in your Shopify Admin.

 

Final Thoughts:

 

This solution worked for me after a lot of trial and error. Shopify, I love your platform, but I was disappointed that neither support nor existing guides could provide a clear solution. I hope this post saves others time and frustration. You can Check this as solved and i hope i can save some people the hours I've wasted...

 

Good luck, Shopify developers and e-commerce managers! May your permalinks work flawlessly! 😊

 

Replies 2 (2)

tobebuilds
Shopify Partner
525 38 139

Thanks for sharing this information. It's good to know!

Founder, Regios Discounts app (4.8 stars, 81 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer

PaulNewton
Shopify Partner
7721 678 1619

 

Very nice thanks @dr_max_owl  always incredibly refreshing to see new poster contribute something so useful to other merchants.

 

While shopify's docs have improved over the years there's still a LOT of a lot of unpolished edges from undocument/undiscussed behavior that is just the result of lack of merchant complaints, gatekept knowledge, or really just the sheer amount of effort it takes to do correctly.

It doesn't help that posts lock after ~3 hours.

 

 

Notes:

  1. Generally want to avoid sending merchants into the DOM soup of most websites.
  2. See find variant id in the help docs  https://help.shopify.com/en/manual/products/variants/find-variant-id
  3. For undocumented behaviors like the the comma seperated discounts merchants should setup testing to know if ever breaks.

 

 

For editing and generating the actual permalinks consider using a custom-liquid section and some utility code like the below.

Optionally modifying the code so that when running in a product or collection template to get the variant ids from that resource

 

{%- comment -%}© 2025 Paul N. permalink maker,  UNTESTED logic example, does not url encode strings etc{%- endcomment -%}
{% liquid #config
  # show cart page instead of going to checkout; true or false
  assign use_storefront = true

  # add variant ids ; seperated by commas ; surrounded by quotes
    # alternatively pull ids from a collection, metafield or metaobject
  assign variantsIDs = '12345,54321'

  # quantities for qty per variant but must be the same amount of entries as variantIDs; seperated by commas ; surrounded by quotes
  # examples: quantities = '1' , quantities = '1,2,4,1'
  assign quantities = '1,3'
  # add discount codes or leave blank ; seperated by commas ; surrounded by quotes
  assign discount_codes = 'DISCOUNT1,DISCOUNT2'
%}

{% liquid
  assign variantsIDs_array = variantsIDs | split:','
  if quantities == blank
    assign quantities = 1
  endif
  assign quantities_array = quantities | split:','
%}
{%- comment -%}build slug i.e. website.com/pages/slug?queryStringParam1=value{%- endcomment -%}
{%- for vIDs in variantsIDs_array -%}
  {%- capture slug -%}
    {{- slug -}}{%- unless forloop.last -%},{%- endunless -%}
    {{- vID -}}:{{- quantities_array[forloop.index] | default:quantities_array[0] -}}
  {%- endcapture -%}
{%- endfor -%}

{% liquid #build querystring i.e. website.com/pages/slug?queryStringParam1=value&queryStringParam2=value
  if use_storefront != blank or discount != blank
    assign querystring = '?'
    if use_storefront
      assign querystring = querystring | append: 'storefront=true' | append: '&'
    endif
    if discount_codes != blank
      assign querystring = querystring | append: 'discount=' | append: discount_codes
    endif
  endif
  # when adding more parameters querystring should be strings with a delimiter then split to an array to be rejoined with an ampersand to avoid missing any ampersands

%}
{{ shop.domain | default: shop.permanent_domain }}{{ slug | strip }}{{- querystring | strip -}}

 

 

 

 

 

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org