Skip to content

Instantly share code, notes, and snippets.

@MarinX
Last active November 13, 2021 15:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarinX/3321f5f82d201a58926a4e260743ab0a to your computer and use it in GitHub Desktop.
Save MarinX/3321f5f82d201a58926a4e260743ab0a to your computer and use it in GitHub Desktop.
Shopify free shipping motivator
function calculateShipping(cart) {
// if total is more than > 50, we have a free shipping
// change me to some number
var FreeShippingPrice = 50;
$(".cart-info").remove();
if (!cart) {
return;
}
var showText = function (text) {
var info = "<div class='cart-info announcement'><p class='announcement__text'>" + text + " </p></div>";
$(".cart-info").remove();
$(".ajaxcart__button").prepend(info);
}
if (cart.total_price > 0) {
var total = cart.total_price / 100;
var until = FreeShippingPrice - total;
if (until <= 0) {
var message = "Good news! Your entire order is eligible for free shipping";
showText(message)
return;
}
var message = "Almost there! You're only $" + until + " away from free shipping";
showText(message);
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment