Last active
November 13, 2021 15:38
-
-
Save MarinX/3321f5f82d201a58926a4e260743ab0a to your computer and use it in GitHub Desktop.
Shopify free shipping motivator
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
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