Guys please help me i want to Add the BUTTON "ADD TO CART in the theme MOTION
what if we want to add “Add to cart” & “Buy now” button on every product on the website?
What can I do if I have a Fetch API issue. I found this code, but I can’t seem to get it to work when I paste it.
// Use fetch API to add the item to the cart
fetch(url, {
method: ‘POST’,
body: formData,
})
.then(response => {
if (response.ok) {
// Redirect to the cart page after adding the item
window.location.href = ‘/cart’;
} else {
// Handle errors here (optional)
console.error(‘Error adding to cart:’, response.statusText);
}
})
.catch(error => {
console.error(‘Fetch error:’, error);
});
});
});