Skip to content

Instantly share code, notes, and snippets.

@aatronco
Last active May 10, 2021 20:42
Show Gist options
  • Save aatronco/40a35805a5b2639e80df4a3e72ee5401 to your computer and use it in GitHub Desktop.
Save aatronco/40a35805a5b2639e80df4a3e72ee5401 to your computer and use it in GitHub Desktop.
<script>
// Define all codes from many promotions
const coupons = ["cupon1", "cupon2", "cupon3"]
//Callback that returns all coupons in cart
var callback_added = function(data) {
console.log(data.coupons)
}
// Callback that searches intersections between the codes in cart and the promotional codes.
// If they intersect, all coupons will be added.
var callbackFunction = function(data) {
cart_coupons = data.coupons
cart_coupons = cart_coupons.split(',');
if (cart_coupons.filter(x => coupons.includes(x))) {
Jumpseller.addCouponToCart(coupons, {
callback: callback_added
})
}
};
$(document).ready(function() {
// Call the function on document load
Jumpseller.getCart({
callback: callbackFunction
})
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment