Prefill cart with URL - but without sending to Checkout or Cart page?

Marcus21
Tourist
5 0 1

Hey all,

I've been reading up on the how-tos for pre-filling carts using a permalink URL - and that works fine.

 

But what I'd like to do is pre-fill a cart, but have the person clicking the link NOT end up either at the cart page or Checkout page.  

 

I really want them to keep shopping, and both those links kind of block that a little bit.

 

Ideally I'd also like a discount pre-applied to the cart too.

0 Likes
korokoro
Shopify Partner
22 2 7

Hi @Marcus21 ,

 

One piece of your puzzle to try out is applying discount codes automatically;

 

https://store.myshopify.com/pages/my-landing-page?discount=MARCUSdiscountcode

 

0 Likes
Marcus21
Tourist
5 0 1

Thanks for your suggestion Korokoro, but I've tried that and it doesn't seem to work for me.

I've tried it both with my domain in the URL and the myshopify version of my shop's domain.

I've also tried it with a couple of different discount codes.

Nothing seemed to translate to a discount code being added to the cart or the checkout.

0 Likes
korokoro
Shopify Partner
22 2 7

I have some ideas but first a question, where do you want them to be redirected to, if not the cart or the checkout?

 

Can you send a link to your store and describe an example of what you want prefilled and where they end up after that?

 

Seems to me to be most logical to end up at the cart page after adding a bunch of products, that way you can see it's happened.

 

You can do that like this;

 

https://mystore.myshopify.com/cart/add?id[]=19635130073174&id[]=19635129319510

where id[]={product-variant}

0 Likes
Marcus21
Tourist
5 0 1

Thanks again korokoro.

I've actually semi solved it.  I wanted people who are offered a special deal via email or landing page, to get the product placed in their cart and a discount code applied, but without landing on the cart or checkout page - as that is not conducive to them continuing to shop further. Especially the checkout page, as linking directly to that doesn't leave the main menu visible.

 

What I ended up using was a combo of two apps.  Automatic Discount and Carter.  One gives me the option to add a discount field to the cart page, the other can create a link that places a discount in the cart and then redirects the user to another page.

 

It also pops up a message saying they've been given a discount. So for this purpose it works perfectly.

I'm sure this is probably possible without using apps, as you have demonstrated, you can do a fair bit with adding variables to the URL. I think that's essentially what these apps are doing.

rwchampin
New Member
3 0 0

Hey man!

Yeah you can absolutely do this with a teeeny tiny bit of javascript.  Just add the variant ID in the url like this:

https://www.your-store.myshopify.com/?variant_id=12345

Then plop this code in your theme like a bossssss:

 

if(!window.location.search){

return;

}

var variantId = parseInt(window.location.search.replace("?variant_id=", ""));

$('[name=id]:visible option').each(function() {

if($(this).val() ==variantId)  {

$(this).prop("selected", "selected")

}else{

$(this).prop("selected", "")

}

})

 

and then sell a whole bunch of Sh!t

0 Likes