Skip to content

Instantly share code, notes, and snippets.

@ardeearam
Last active July 5, 2020 02:03
Show Gist options
  • Select an option

  • Save ardeearam/4617bbf33f27ada317b6213c279f87d2 to your computer and use it in GitHub Desktop.

Select an option

Save ardeearam/4617bbf33f27ada317b6213c279f87d2 to your computer and use it in GitHub Desktop.
theme.ShippingBar = (function(theme) {
var bar = document.querySelector('.announcement-bar');
if(bar)
{
var promote_txt = bar.dataset.promote;
var unlocked_txt = bar.dataset.unlocked;
var treshold = bar.dataset.treshold;
}
function update()
{
if(bar)
{
$.getJSON('/cart.js').then(
function(cart) {
var value_left = treshold - cart.total_price;
var value_left_money = theme.Currency.formatMoney(value_left,theme.moneyFormat);
if(value_left <= 0){
bar.innerHTML = '<p class="announcement-bar__message">' + unlocked_txt + '</p>';
}
else{
bar.innerHTML = '<p class="announcement-bar__message">' + promote_txt.replace('[value]',value_left_money) + '</p>';
}
}
);
}
}
return { update:update }
}) (theme);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment