Schrijf je nu in voor onze nieuwsbrief & ontvang een welkomstkorting van 15%! Wij houden je op de hoogte van (exclusieve) kortingen, de nieuwste items en nog véél meer!
Een selectie kiezen resulteert in het geheel verversen van de pagina.
Opent in een nieuw venster.
document.addEventListener('DOMContentLoaded', function () {
const donationCheckbox = document.getElementById('donation-checkbox');
const donationVariantId = 10068320387408; // Your donation product's variant ID
if (!donationCheckbox) return;
donationCheckbox.addEventListener('change', function () {
if (donationCheckbox.checked) {
// Add the donation product to the cart
fetch('/cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
items: [{
id: donationVariantId,
quantity: 1
}]
})
})
.then(res => res.json())
.then(data => {
console.log("Donation added:", data);
location.reload(); // Reload the page to update cart
})
.catch(err => console.error("Error adding donation:", err));
} else {
// Remove the donation product from the cart
fetch('/cart.js')
.then(res => res.json())
.then(cart => {
const item = cart.items.find(i => i.variant_id === donationVariantId);
if (item) {
return fetch('/cart/change.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
id: item.key,
quantity: 0
})
});
}
})
.then(() => {
console.log("Donation removed");
location.reload(); // Reload the page to update cart
})
.catch(err => console.error("Error removing donation:", err));
}
});
});