Skip to content

Instantly share code, notes, and snippets.

@ihorduchenko
Last active July 14, 2020 16:48
Show Gist options
  • Save ihorduchenko/2989cb53acaddf16cfa0dda4a231f021 to your computer and use it in GitHub Desktop.
Save ihorduchenko/2989cb53acaddf16cfa0dda4a231f021 to your computer and use it in GitHub Desktop.
Shopify built in currency switcher
{%- form 'localization', class: 'selectors-form' -%}
<select id="currency-list">
{% for currency in form.available_currencies %}
<option{% if currency.iso_code == form.current_currency.iso_code %} selected="true"{% endif %}
data-name="{{ currency.name }}" value="{{ currency.iso_code }}">
{%- if currency.symbol -%}{{ currency.symbol }}{%- endif -%} {{ currency.iso_code }}
</option>
{%- endfor -%}
</select>
<input id="currentCurrencyInp" type="hidden" name="currency_code" value="{{ form.current_currency.iso_code }}">
{%- endform -%}
<script>
$('#currency-list').on('change', function() {
var vall = $(this).val();
$('#currentCurrencyInp').val(vall);
setTimeout(function() {
$('#localization_form').submit();
}, 100);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment