Hi guys!
I need to add a product to the ‘cart’ when I click a button in the checkout page, is that possible?
I’ve tried adding via AJAX → cart.js but it’s not working.
*PS: the store is Shopify Plus
Hi guys!
I need to add a product to the ‘cart’ when I click a button in the checkout page, is that possible?
I’ve tried adding via AJAX → cart.js but it’s not working.
*PS: the store is Shopify Plus
Hello @will-silveira ,
Using cart.js is the way to go. Don’t forget to reload the page once is done in order to see the changes.
fetch(‘/cart/add.js’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
},
body: JSON.stringify({ quantity: 1, id: free_variant_id })
})
.then(response => response.json())
.then(response => {
window.location.reload();
})