Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi, I am wondering if anybody knows how to create a permalink that autofills my cart with specific products. But, instead of taking the user to the checkout page, it takes them to a specific product page.
This is the URL I have generated that fills the cart: https://pecosoutdoor.com/cart/add/?id[]=41529975374029&id[]=40184234016973&id[]=40184233590989
This is the product page I would like the user to arrive at with a full cart: https://pecosoutdoor.com/products/the-pecos-table?variant=41111205216461
Thanks so much.
Hi @conchousa
You can custom code this feature in your store.
The problem with your logic is what will happen when URL will have more than 1 product will your redirect URL will be same every time?
Yes, I will always want the user to be redirected to the same product page.
Could you help me do this?
Hi @conchousa
You can use the below script to add a product in the cart and redirect to your URL
var addautocart = getQuerystringNameValue('auto_addcart');
if(addautocart != null){
cartList = addautocart.split(",");
var cartItem = [];
for(var _c=0; _c < cartList.length; _c++){
_cart = cartList[_c].split(":")
_cItem = {};
if(_cart.length > 1){
_cItem.id = _cart[0];
_cItem.quantity = _cart[1];
cartItem.push(_cItem);
}
}
setTimeout(function(){
fetch(window.Shopify.routes.root + 'cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: cartItem
})
.then(response => {
location.href = "Product URL";
return response.json();
})
.catch((error) => {
console.error('Error:', error);
});
},500)
}
For the query parameters function please visit the below URL
https://www.growyourgk.com/get-querystring-value/
Your auto-add cart URL would be like this.
https://pecosoutdoor.com?auto_addcart=[variantid]:[qty],[variantid]:1
where variantid is the product variant ID and after : QTY you want to add to the cart.
Hope this will help...
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024