Add to cart with javascript and redirect right to checkout

Eligijus_Lipski
Shopify Partner
10 0 5

Hey there,

I've seen some apps do It, but i can't figure out how. I save all of the cart items to my own database and after some time I want to create a checkout with javascript. I add the items to the cart using "POST /cart/add.js", but after I've added the products, how do I programatically redirect to the checkout page ?

Recart is doing it somehow!

 

HymnZ
Shopify Partner
389 4 50

You can use permalinks for checkout. You can skip adding to cart and directly take them to checkout.

https://<your_store_link>/cart/<variant_id>:<variant_quantity>?checkout

 

My speciality lies in making Shopify work for your requirements, not the other way round. HMU on email: hymnz@outlook.com or on skype: hymnzzy

If you like my work, consider supporting me :) https://www.buymeacoffee.com/hymnz
Eligijus_Lipski
Shopify Partner
10 0 5

HymnZ this is the correct answer! Thanks!

0 Likes
Jason
Shopify Expert
10360 158 2008

Just keep in mind that there is a difference between the permalink and the AJAX method discussed here. One will create a cart, the other only a checkout. This is an important difference.

So if the customer has items in the cart already, the permalink method will ignore those and create a checkout with only the permalink items.

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
longhairforme
Tourist
5 0 0

Were you able to figure out a solution?

0 Likes
chenster
Pathfinder
104 4 11

SO @HymnZ solution is more like Amazon Buy Now button without adding it to current cart.

 
Cartoo
0 Likes
HymnZ
Shopify Partner
389 4 50

@chenster .. I answered what the OP asked. If you need the intermediary step to add to cart and then proceed to checkout, follow up "POST /cart/add.js" with location redirect to "/checkout"

My speciality lies in making Shopify work for your requirements, not the other way round. HMU on email: hymnz@outlook.com or on skype: hymnzzy

If you like my work, consider supporting me :) https://www.buymeacoffee.com/hymnz
0 Likes