Last active
January 10, 2023 03:00
-
-
Save heri/d368d81f7a909474bf8db6bdf41cffbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.getJSON('/cart.js', function(cart) { | |
items = cart.items; | |
var results = items.filter(x => x.id === 6223106801703); | |
if ((results.length == 0) && (items.length > 0)) { | |
jQuery.post('/cart/add.js', { | |
quantity: 1, | |
id: 6223106801703 | |
}); | |
location.reload(); | |
} | |
if (results.length > 0 ) { | |
if ((results.length == 1) && (items.length == 1)) { | |
// remove free gift if there are no other products in cart | |
jQuery.post('/cart/update.js', {updates: {6223106801703: 0}}); | |
} else { | |
// update free gift gift to quantity = 1, for customers adding multiple free gifts | |
jQuery.post('/cart/update.js', {updates: {6223106801703: 1}}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace 6223106801703 with the id of the free product