What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: Pre-load cart with subscription/plan products using permalinks

Solved

Pre-load cart with subscription/plan products using permalinks

Jinxo
Tourist
3 0 3

Can permalink attributes be used to pre-load the cart with subscription/plan products? There's an option to include a product variant id, but can we include a plan id?

Accepted Solution (1)
Phillip_Malboeu
Shopify Partner
21 2 19

This is an accepted solution.

Hey @Jinxo and @saeba!

I believe I figured it out, this url will clear the cart, add items with a selling_plan and then redirect to checkout:
`https://{SHOP}.myshopify.com/cart/clear?return_to=/cart/add?items[][id]={VARIANT_ID}%26items[][quantity]={QUANTITY}%26items[][selling_plan]={SELLING_PLAN_ID}%26return_to=/checkout`

To head to the cart page instead of directly to checkout, you can remove the `%26return_to=/checkout`.

Cheers,
Phil

View solution in original post

Replies 52 (52)

saeba
Tourist
6 0 3

I have a same question.

Phillip_Malboeu
Shopify Partner
21 2 19

Would love to have an answer to this as well.

Phillip_Malboeu
Shopify Partner
21 2 19

This is an accepted solution.

Hey @Jinxo and @saeba!

I believe I figured it out, this url will clear the cart, add items with a selling_plan and then redirect to checkout:
`https://{SHOP}.myshopify.com/cart/clear?return_to=/cart/add?items[][id]={VARIANT_ID}%26items[][quantity]={QUANTITY}%26items[][selling_plan]={SELLING_PLAN_ID}%26return_to=/checkout`

To head to the cart page instead of directly to checkout, you can remove the `%26return_to=/checkout`.

Cheers,
Phil

saeba
Tourist
6 0 3

Yes that works!

Thanks Phillip!

Jinxo
Tourist
3 0 3

Awesome! I'll try it out. 

kevnord
Visitor
2 0 0

This worked! Thank you so much for posting the solution. I was pulling my hair out.

achieve
Visitor
2 0 1

Hi Phillip, thank you for providing the solution to add a subscriptions product directly to the cart.  I can't figure out how to add a second or subsequent variant and quantity.  Can you assist?

happygree
Visitor
1 0 0

Hi, have you figured this out? I still don’t understand how to add additional subsequent variants.

Phillip_Malboeu
Shopify Partner
21 2 19

Hi @happygree and @achieve,

Sorry for the late reply! You can always add more variants by adding more `items[][id]`, like so:
`https://{SHOP}.myshopify.com/cart/clear?return_to=/cart/add?items[][id]={VARIANT_ID}%26items[][quantity]={QUANTITY}%26items[][selling_plan]={SELLING_PLAN_ID}%26items[][id]={SECOND_VARIANT_ID}%26items[][quantity]={SECOND_QUANTITY}%26items[][selling_plan]={SELLING_PLAN_ID}%26return_to=/checkout`

Cheers,
Phil

achieve
Visitor
2 0 1

Thank you Phil, that worked perfectly!

WowieDogs
Tourist
5 0 1

Phil,

I was able to use this to add my product with its specific plan to the cart, but then I was also trying to add another item to the cart (free upgrade for first month when signing up for 6 or 12 month plan) but it doesn’t seem to want to add the second product because it is not a subscription product - any thoughts? And I would like to have it add it at a zero cost.

Thanks!

Phillip_Malboeu
Shopify Partner
21 2 19

Hi @WowieDogs!

You should be able to have non-subscription and subscription products in the same cart, it works for me so the issue is most likely somewhere else. Could you write up an example of what you're inputing?

As for the 0$ product, there's multiple ways to get that done I believe, you could have a 0$ variant of that product or have a discount code that sets that particular product to 0.

Let me know if I've answered your questions, cheers,
Phil

WowieDogs
Tourist
5 0 1

Hi!

I can't seem to get two products in the cart even if they are non-subscription, so I feel like I'm doing something wrong. For this link:

https://wowiedogs.myshopify.com/cart/add/?id=33005749469277&quantity=1&id=39277088309341&quantity=1

it only adds the second one to the cart. If I reverse the order, it also just adds the second one.

I've tried:

https://wowiedogs.myshopify.com/cart/add/?id=33005749469277&quantity=1,id=39277088309341&quantity=1

I've also done the :1 for the quantity and that won't work at all.

Any thoughts?

Thanks!

Julie

Phillip_Malboeu
Shopify Partner
21 2 19

Ah take a look at the accepted solution @WowieDogs, the `items[]` before each argument are important! It makes it so you're sending an array to the server.

WowieDogs
Tourist
5 0 1
Click to expand...
Ah, yes, I figured I was missing something!! It worked!! Thank you so much!!


Mgrohne
Visitor
1 0 0

Trying to create a cart permalink with one subscription item (selling plan) and one regular item. I can get it to work with the subscription item but when I add a second product i get an error. What am I doing wrong?

 

THIS WORKS FOR JUST SUBSCRIPTION PRODUCT:

https://marea-wellness.myshopify.com/cart/clear?return_to=/cart/add?items[][id]=42924348145883%26ite...

 

THIS DOES NOT WORK WHEN ADDING 2ND PRODUCT

https://marea-wellness.myshopify.com/cart/clear?return_to=/cart/add?items[][id]=42924348145883%26ite...

Deep199
Visitor
1 0 0

This is not working for me , so I used this

 

 

 

function joinToday(type){ 
$.get('/cart/clear',()=>{
if(type=='monthly'){
window.location.href = "/cart/add?items[][id]={varId}&items[][quantity]=1&items[][selling_plan]={planId}&items[][id]={varId}&items[][quantity]=1&return_to=/checkout";
}else if(type == 'yearly'){
window.location.href = "/cart/add?items[][id]={varId}&items[][quantity]=1&items[][selling_plan]={planId}&return_to=/checkout";
}
});
}

 

 

Amelia7
Visitor
2 0 0

Hey @Phillip_Malboeu , thank you so much for this great solution. It works very well - I'm just wondering if you can add a discount code on to it somehow, as you can with permalinks like the below?

e.g. https://{SHOP}.myshopify.com//cart/39434614276148:1,39408637149236:1?discount=MEMBERSHIP

I put a ?discount=MEMBERSHIP at the end of your suggested URL but I guess it's never going to like two question marks.

https://{SHOP}.myshopify.com/cart/clear?return_to=/cart/add?items[][id]={VARIANT_ID}%26items[][quant...

Thanks so much.

Phillip_Malboeu
Shopify Partner
21 2 19

Hey @Amelia7, no worries!

Adding a `%26discount=MEMBERSHIP` would do it. %26 is the URL encoding of the &.

Cheers,
Phil

Amelia7
Visitor
2 0 0

You're amazing, thank you so much!

techadmin
Visitor
2 0 0

I can't get the discount code to work. I've tried moving it to different locations in the URL but none of them seem to work.  
https://{SHOP}.myshopify.com/cart/clear?return_to=/cart/add?items[][id]=39619404562467%26items[][quantity]=1%26items[][selling_plan]=524091427%26discount=MYDISCOUNTCODE%26return_to=/checkout

Jacob_Becher
Shopify Partner
29 0 85

@techadmin can you try this format:

 

https:///SHOP-NAME/discount/DISCOUNT_CODE/?redirect=/cart/add?items[][id]=ITEM_ID%26items[][quantity]=QUANTITY%26items[][selling_plan]=SELLING_PLAN_ID%26return_to=/checkout

techadmin
Visitor
2 0 0

YES! That works, thank you.

 

Jacob_Becher
Shopify Partner
29 0 85

Great!  Glad to help.

darzouras
Shopify Partner
1 0 0

When I try this pattern I get an error: "Parameter Missing or Invalid: Required parameter missing or invalid: items".

It's pretty important to the flow that I'm trying to manage that I'm also able to clear the cart as well but haven't been able to find a permalink combination of cart clear / cart add / set discount (that supports subscriptions) that is working. Has anyone had any luck with this combination?

amanda3e
Shopify Partner
3 0 0

I'm having the exact same issue.

Yasaman
Shopify Partner
3 0 2

Hi Darzouras,

 

Yasaman's here from the Subify subscription app.

You can use this permalink for the mentioned requirements:

https://[MY STORE].myshopify.com/cart/clear?return_to=/cart/add?items[][id]=[VARIANT ID]%26items[][quantity]=1%26items[][selling_plan]=[SELLING PLAN ID]%26return_to=/checkout?discount=[SHOPIFY DISCOUNT CODE] 

 

As an example, this is the created permalink for our demo store:
Password is: 1234

https://subify-demo.myshopify.com/cart/clear?return_to=/cart/add?items[][id]=42408847540456%26items[...

 

Hope this will be helpful.

@amanda3e, guess you had the same question. 

Customer Success Manager at Subify subscription app
DanialE
Shopify Partner
1 0 0

Hi, Is there any way to also pre-populate the checkout fields with the permalink while a product with subscription is added. Similar to the below link but subscription is also added to the product: https://shopify.dev/docs/apps/channels/cart-permalinks/cart-permalinks

 

Alternatively, is there a way to add address and other checkout fields to the below permalink:https://[MY STORE].myshopify.com/cart/clear?return_to=/cart/add?items[][id]=[VARIANT ID]%26items[][quantity]=1%26items[][selling_plan]=[SELLING PLAN ID]%26return_to=/checkout?

d_tehrani
Shopify Partner
56 1 13

Hi.

This is really helpful, but I couldn't find any official documentation about the URL query params for subscriptions. Is this method officially supported by Shopify? Or is there a possibility that this method will stop working someday?

Thanks.

d_tehrani
Shopify Partner
56 1 13

(I didn't mention anyone in the above post, so just in case.)

Hi.

 @Phillip_Malboeu 

Is there any possibility that you could share your ideas on this?

https://community.shopify.com/c/shopify-design/pre-load-cart-with-subscription-plan-products-using-p...

Phillip_Malboeu
Shopify Partner
21 2 19

Hey @d_tehrani,

Well can't be sure, but I based the previous answers on the Cart ajax API: https://shopify.dev/api/ajax/reference/cart
I'm trusting it!

Cheers,
Phil

d_tehrani
Shopify Partner
56 1 13

Hi @Phillip_Malboeu,

Got it, thank you very much for the reply.

coysammy
Visitor
1 0 0

Hey @Phillip_Malboeu, I am trying to build a link that takes customers to a cart page (not checkout page) - that is pre loaded with any combo of subscriptions / one time products. I then want a discount code to be auto applied when they get to checkout based on the code I put in the URL, I am trying this but it isn't working:


https://[MY STORE].myshopify.com/cart/clear?return_to=/cart/add?items[][id]=[VARIANT ID]%26items[][quantity]=1%26items[][selling_plan]=[SELLING PLAN ID]%26items[][id]= [VARIANT ID] %26items[][quantity]=1?discount=[DISCOUNT CODE]

 

Any ideas on how I can get this to work?

 

Thanks

Sam

Phillip_Malboeu
Shopify Partner
21 2 19

Hey @coysammy,

Could you try %26discount= instead of ?discount=?

Let me know!

Phil

VSozinov
Visitor
2 0 0

Hi, @Phillip_Malboeu! I have the same question about discount applying to permalink, as @coysammy. Adding "%26discount=my_discount_code_here" at the end of permalink doesn't work. If I add promocode manually it works as expected. Any ideas?

Jacob_Becher
Shopify Partner
29 0 85

Hi @Phillip_Malboeu thank you for this excellent solution!  One question: is there any way to structure the link so the customer does not see the "cart" breadcrumb in checkout?  We want to prevent the customer from navigating back to the cart.

 

When we create a "checkout link" as described below, the product gets sent straight to checkout and the "cart" breadcrumb is not visible.

https://help.shopify.com/en/manual/products/details/checkout-link

 

The only problem is, it sends the product as a one-time product instead of a subscription product, and the subscription is essential in our case

 

Any way to get the best of both worlds here?

 

Thanks!!

Jacob_Becher
Shopify Partner
29 0 85

Hi @VSozinov after puzzling with this for a bit, I found out a way to do this:

 

https://SHOPNAME.myshopify.com/discount/DISCOUNTCODE/?redirect=/cart/add?items[][id]=VARIANTID%26ite...

 

That works for me and puts the discount into scheckout automatically.

VSozinov
Visitor
2 0 0

Thank you very much! It helped me

 

Rronz1
Shopify Partner
6 1 2

Any clue on how to add attributes to this? I know it has been a long time but I am kinda blocked and this has proved to be very useful.

phillipmalboeuf
Shopify Partner
2 0 1

Hi @Rronz1!

You can try: `https://{SHOP}.myshopify.com/cart/clear?return_to=/cart/add?items[][id]={VARIANT_ID}%26items[][quantity]={QUANTITY}%26items[][selling_plan]={SELLING_PLAN_ID}%26items[][properties][{ATTRIBUTE}]={ATTRIBUTE_VALUE}%26return_to=/checkout`

If it helps, I mentioned in a previous reply here that it's all based on the Cart ajax API: https://shopify.dev/docs/api/ajax/reference/cart

Cheers,

Phil

cglodt
Visitor
3 0 0

Hi Phillip! Are you able to help me with creating a link for my store for this exact issue? 

mktgadminHologr
Shopify Partner
1 0 0

I am trying to do this for a subscription product + two non-subscription products and discount.

It adds all of the products and the discount but it set the first product for one time purchase instead of subscription.  Here is the base product page for reference -
`shop.myphenology.com/products/morning-evening-gummy-duo-supplements`

Here is the permalink I'm working with-
`shop.MyPhenology.com/cart/39853678231617:1,39853677903937:1,39870377590849:1?selling_plan=578977857?discount=SamplerGift`

mambochan
Visitor
1 0 1

Hello @Phillip_Malboeu 

This setup works great! However, for some reason, when I append any of the UTM query parameters to the link, none of the values are being recorded in the "Conversion Summary". 


EXAMPLE:

https://{SHOP}.myshopify.com/cart/clear?return_to=/cart/add?items[][id]={VARIANT_ID}%26items[][quantity]={QUANTITY}%26items[][selling_plan]={SELLING_PLAN_ID}%26return_to=/checkout%26utm_source=test 

Is there a workaround for this? 

tbambara
Shopify Partner
1 0 0

@Phillip_Malboeu, thank you for this article, it was extremely helpful!

 

Have you had any success creating a mixed cart permalink?  My store features both subscription and single purchase selling plans, and we'd love to be able to create pre-loaded carts via permalink with our subscription products PLUS a one-time product for the customer to try. 

Do you think this is possible?

scotts1
New Member
4 0 0

If there was a way to find out the selling id I would be possibly be able to do this.  

So far, I have not found a way to do it.

Rronz1
Shopify Partner
6 1 2

@tbambara @scotts1 I have managed to do a mix between subscription and "normal" one-time products it looks something like this: 

${shopUrl}/clear?return_to=/cart/add?items[][id]=${variantId}%26items[][quantity]=1%26items[][selling_plan]=${sellingPlan}
%26items[][id]=${oneTime}%26items[][quantity]=1
%26return_to=/checkout


Not sure if you want to do it manually or generate it automatically I do it automatically, I basically check if the selected product exists in my subscription app and then if it does I get it's selling plan via graphQL with the query below: 
`query {
        product(id:"gid://shopify/Product/${productId}"){
              sellingPlanGroups(first:10) {
                edges {
                  node {
                    id
                    sellingPlans(first:10){
                      edges{
                        node{
                          id
                        }
                      }
                    }
                  }
                }
              }
            }
          }`

I suppose even doing it manually you can use the shopify graphQL app to get the selling plan with the same query just by replacing the productID. Hope that helps
scotts1
New Member
4 0 0

In case you are still around, this is something I am trying to do now and cannot seem to get done right.

 

Here is an example of one link for a product that is working fine  https://d7ea93.myshopify.com/cart/clear?return_to=%2Fcart%2Fadd%3Fitems%5B0%5D%5Bid%5D%3D45203860914...

 

Here is the product I am trying to do it for  

{"product":{"id":8565646623010
product variant: 46559953486114
selling id 5905056034

 

This is what I have tried to do so far and it isn't working  https://d7ea93.myshopify.com/cart/clear?return_to=/cart/add?items8565646623010id=46559953486114%26it...

 

What am I missing?   

scotts1
New Member
4 0 0

Hello in case you are still around, I am still trying to figure this out.

 

Here is an example of a link for a different product that is working with the selling plan/subscription  https://d7ea93.myshopify.com/cart/clear?return_to=%2Fcart%2Fadd%3Fitems%5B0%5D%5Bid%5D%3D45203860914...

 

That is what it is supposed to look like.  

 

I am also following the example you gave but must be missing something about how it is put together right. 

'

This is the product and selling plan I am trying to use it for  

 

{"product":{"id":8565646623010
product variant: 46559953486114
selling id 5905056034

 

Here is the attempt I have so far:

 

https://d7ea93.myshopify.com/cart/clear?return_to=/cart/add?items8565646623010id=46559953486114%26it...

 

 

What am I missing?     Thanks.

 

wcolton48
Shopify Partner
38 0 12

Any suggestion on the format that WOULD NOT clear the cart? It would just add the product?