Why won't the permalink add the correct quantity to the cart?

Does anybody know why this permalink wont add the product to the cart with the correct quantity(2)?

onclick = "window.location.href='https://biggers-market.myshopify.com/cart/add?id=7694095483049:2';"

If I remove the ‘:2’ the button works just fine and populates the cart with the correct item

Hello @BB_Tech

You can try this code:


Let us know if it works

Regards,

Ali Reviews team.

1 Like

That’s a wrong URL format.

You can either:

a) add to cart and go to cart page, in which case it should look like:

https://biggers-market.myshopify.com/cart/add?id=42877880828073&quantity=5

b) go directly to checkout with this product, in which case url should look like:

https://biggers-market.myshopify.com/cart/42877880828073:3

Only the second one is called permalink.

See https://community.shopify.com/c/shopify-design/cart-use-permalinks-to-pre-load-the-cart/td-p/613702

1 Like

Thank you so much, I am having a lot of trouble with this. Is there a link format that will add to the cart without redirecting to the cart page? I have a very strange corner case I need for a few products and have to manually code an add to cart button. Also if you have know of any sort of documentation for this, I cant find it anywhere.

Usually this is done via JS, using Ajax Cart or alike.

Because if you follow a link, then you’re leaving the current page. Shopify supports a return_to parameter to instruct the system to redirect you back after adding to cart, but this is cumbersome and not pleasant experience.

Your theme includes necessary code for adding to cart with JS, just needs proper configuration/modification.

There is a ‘Quick add to cart’ option for product grids and ‘Featured product’ section when you want to showcase a single product, it could be that the reasonable solution would not require any coding.

1 Like

Thanks @tim_1 that is helpful. So for my case it is a subscription only type store but with every subscription app I have tried it can not be configured to the quick add button on a collection page. . So far I have been able to add the code

onclick = "window.location.href='https://biggers-market.myshopify.com/cart/add?id={{ card_product.selected_or_first_available_variant.id }}&selling_plan=1161986217';"

which works to add the selected product to the cart with its associated subscription, but I can not figure out how to add the quantity part or keep it from redirecting. I am not very knowledgable with js or ajax but could learn if this would be the only way to fix the problem. If you have any suggestions or recommendations at all I would love to hear them.

I have tried this as well for quantity

onclick = "window.location.href='https://biggers-market.myshopify.com/cart/add?id={{ card_product.selected_or_first_available_variant.id }}&quantity={{ card_product.selected_or_first_available_variant.quantity }}&selling_plan=1161986217';"

Not sure if you are getting my replies or not, I am going to direct message you

sorry for all the replies, laggy internet