Personalized checkout and custom promotions with Shopify Scripts
Hi community
I use a page designer and I need the Javascript to allow me to add a product to the cart.
Anyone who knows what the code is?
I have used this, but I can't seem to make that work
fetch( "/cart/update.js", { method: "POST", headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ updates: {}, sections: ["cart-drawer", "cart-icon-bubble"] }) } ).then(res => res.json()) .then(cartData => { const cart = document.querySelector('cart-drawer') cart.renderContents(cartData) }) document.querySelector('cart-drawer.drawer').classList.remove('is-empty');
use the below script to add an item to the cart.
let formData = {
'items': [{
id: 36110175633573,
quantity: 2
}]
};
fetch(window.Shopify.routes.root + 'cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
})
.then(response => {
return response.json();
})
.catch((error) => {
console.error('Error:', error);
});
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024