Skip to content

Instantly share code, notes, and snippets.

@git-willie
Created May 26, 2019 21:57
Show Gist options
  • Save git-willie/7b5facb3e64fc7488ccfcfaf169c6a47 to your computer and use it in GitHub Desktop.
Save git-willie/7b5facb3e64fc7488ccfcfaf169c6a47 to your computer and use it in GitHub Desktop.
Dynamic sales motivator message
// Display motivator message
ShopifyAPI.saleMotivator = function(cart, cart_motivator_goal, motivator_msg_selector) {
var cart_subtotal = parseFloat(cart.total_price / 100).toFixed(2);
var cart_motivator_goal = cart_motivator_goal;
var cart_motivator_goal_remaining = parseFloat(cart_motivator_goal - cart_subtotal).toFixed(2);
var motivator_msg = motivator_msg_selector;
if (cart_subtotal == 0) {
motivator_msg.html('FREE SHIPPING ON ORDERS OVER $' + cart_motivator_goal);
} else {
if (cart_subtotal >= cart_motivator_goal) {
motivator_msg.html('AWESOME, YOU NOW QUALIFY FOR FREE SHIPPING!');
} else {
motivator_msg.html('NICE - JUST SPEND $' + cart_motivator_goal_remaining + ' MORE AND GET FREE SHIPPING!');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment