FROM CACHE - en_header

Pre-load cart with subscription/plan products using permalinks

Solved
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)

Accepted Solutions
Phillip_Malboeu
Shopify Partner
21 2 14

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 35 (35)
saeba
Tourist
6 0 3

I have a same question.

Phillip_Malboeu
Shopify Partner
21 2 14

Would love to have an answer to this as well.

Phillip_Malboeu
Shopify Partner
21 2 14

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
New Member
2 0 0

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

achieve
New Member
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
New Member
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 14

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
New Member
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 14

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 14

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!!


Amelia7
New Member
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 14

Hey @Amelia7, no worries!

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

Cheers,
Phil

Amelia7
New Member
2 0 0

You're amazing, thank you so much!

d_tehrani
Shopify Partner
56 1 10

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.