Make a lasting impression with our Corporate Gift Baskets. Thoughtfully curated with premium Kentucky products, these baskets are perfect for clients, employees, and business occasions.
Choosing a selection results in a full page refresh.
Opens in a new window.
document.addEventListener("DOMContentLoaded", function () {
console.log("Free Gift Script loaded successfully!");
// Free Gift Variant ID
const FREE_GIFT_VARIANT_ID = "43792888627244"; // Replace with your free gift's Variant ID
const PROMO_END_DATE = new Date("2025-10-05T23:59:59Z"); // Set the promotion end date
// Function to check the cart and apply the free gift logic
function checkCartForFreeGift() {
console.log("Checking cart for free gift...");
fetch("/cart.js")
.then((response) => response.json())
.then((cart) => {
console.log("Cart data fetched:", cart);
const subtotal = cart.items_subtotal_price / 100; // Convert to dollars
console.log("Cart subtotal:", subtotal);
const hasFreeGift = cart.items.some(
(item) => item.variant_id === parseInt(FREE_GIFT_VARIANT_ID)
);
console.log("Does the cart already have the free gift?", hasFreeGift);
// Check if the promotion is still active
if (new Date() > PROMO_END_DATE) {
console.log("Promotion has ended.");
if (hasFreeGift) {
removeFreeGift();
}
return;
}
// Add or remove the free gift based on the subtotal
if (subtotal >= 50 && !hasFreeGift) {
console.log("Adding free gift...");
addFreeGift();
} else if (subtotal < 50 && hasFreeGift) {
console.log("Removing free gift...");
removeFreeGift();
} else {
console.log("No action needed.");
}
})
.catch((error) => {
console.error("Error fetching cart data:", error);
});
}
// Function to add the free gift
function addFreeGift() {
fetch("/cart/add.js", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: FREE_GIFT_VARIANT_ID, // Use the Variant ID here
quantity: 1,
}),
})
.then((response) => {
if (response.ok) {
console.log("Free gift added successfully!");
} else {
console.error("Failed to add free gift:", response);
}
})
.catch((error) => {
console.error("Error adding free gift:", error);
});
}
// Function to remove the free gift
function removeFreeGift() {
fetch("/cart.js")
.then((response) => response.json())
.then((cart) => {
const lineItem = cart.items.find(
(item) => item.variant_id === parseInt(FREE_GIFT_VARIANT_ID)
);
if (lineItem) {
fetch("/cart/change.js", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
line: lineItem.key, // Use the line item key to remove it
quantity: 0,
}),
})
.then((response) => {
if (response.ok) {
console.log("Free gift removed successfully!");
} else {
console.error("Failed to remove free gift:", response);
}
})
.catch((error) => {
console.error("Error removing free gift:", error);
});
}
})
.catch((error) => {
console.error("Error fetching cart data for removal:", error);
});
}
// Run the check on page load and cart updates
checkCartForFreeGift();
document.addEventListener("cart:updated", checkCartForFreeGift);
});