Skip to content

Instantly share code, notes, and snippets.

@willbroderick
Forked from carolineschnapp/currencies.liquid
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willbroderick/dbb4064ba345790b39f9 to your computer and use it in GitHub Desktop.
Save willbroderick/dbb4064ba345790b39f9 to your computer and use it in GitHub Desktop.
Keeps the 'You have chosen GBP, but the shop is AUS' message hidden, if you're using the native currency
{% if settings.show_multiple_currencies %}
{{ "//cdn.shopify.com/s/javascripts/currencies.js" | script_tag }}
{{ "jquery.currencies.min.js" | asset_url | script_tag }}
<script>
{% if settings.currency_format %}
Currency.format = '{{ settings.currency_format }}';
{% endif %}
var shopCurrency = '{{ shop.currency }}';
/* To do every time the currency is set */
function onCurrencyChange(){
jQuery('.selected-currency').text(Currency.currentCurrency);
jQuery('.if-currency-different').toggle(Currency.currentCurrency != shopCurrency); // visibility of currency-different notice
}
/* Sometimes merchants change their shop currency, let's tell our JavaScript file */
Currency.moneyFormats[shopCurrency].money_with_currency_format = {{ shop.money_with_currency_format | strip_html | json }};
Currency.moneyFormats[shopCurrency].money_format = {{ shop.money_format | strip_html | json }};
/* Default currency */
var defaultCurrency = '{{ settings.default_currency }}' || shopCurrency;
/* Cookie currency */
var cookieCurrency = Currency.cookie.read();
/* Fix for customer account pages */
jQuery('span.money span.money').each(function() {
jQuery(this).parents('span.money').removeClass('money');
});
/* Saving the current price */
jQuery('span.money').each(function() {
jQuery(this).attr('data-currency-{{ shop.currency }}', jQuery(this).html());
});
// If there's no cookie.
if (cookieCurrency == null) {
if (shopCurrency !== defaultCurrency) {
Currency.convertAll(shopCurrency, defaultCurrency);
}
else {
Currency.currentCurrency = defaultCurrency;
}
}
// If the cookie value does not correspond to any value in the currency dropdown.
else if (jQuery('[name=currencies]').size() && jQuery('[name=currencies] option[value=' + cookieCurrency + ']').size() === 0) {
Currency.currentCurrency = shopCurrency;
Currency.cookie.write(shopCurrency);
}
else if (cookieCurrency === shopCurrency) {
Currency.currentCurrency = shopCurrency;
}
else {
Currency.convertAll(shopCurrency, cookieCurrency);
}
jQuery('[name=currencies]').val(Currency.currentCurrency).change(function() {
var newCurrency = jQuery(this).val();
Currency.convertAll(Currency.currentCurrency, newCurrency);
onCurrencyChange();
});
var original_selectCallback = window.selectCallback;
var selectCallback = function(variant, selector) {
original_selectCallback(variant, selector);
Currency.convertAll(shopCurrency, jQuery('[name=currencies]').val());
onCurrencyChange();
};
onCurrencyChange();
</script>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment