I am trying to add a button that says “Donate” to Shopify and when clicked will increase the carts total by 10% and add a product to the cart called Donation. I would like customers to be able to click this before they start shopping.
Hi landgrove,
If you understand the code please use the below script code to add the functionality in click of button.
let formData = {
‘items’: [{
‘id’: 36110175633573,
‘quantity’: 1
}]
};
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);
});
Don’t forget to replace the I’d with your real donation product id.
For more detail please refer to the below URL.
https://shopify.dev/docs/api/ajax/reference/cart
Hope this will help…
Let me know if you are willing to hire someone to accomplish the same.
I do not understand code. I have sent you an email to possibly work together to solve this.