Adding a Button that Increases Cart total

landgrove
New Member
5 0 0

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.

Replies 2 (2)

gr_trading
Shopify Partner
1580 138 168

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.

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee
landgrove
New Member
5 0 0

I do not understand code. I have sent you an email to possibly work together to solve this.