Currency Switcher - Check Currency URL and Apply Current Class

This technique was first used on the http://bastille-eu.myshopify.com/ shop and is built to be used with the OLM base theme.

Benefit: instead of manually updating the currency selector for each currency, apply this code and the store will auto apply.

  1. Assign the shop domain to the vaviable shopcurrency
  2. Check if the domain contains a currency code and if it does apply the currency_current class.

Note: This technique requires the domains to be set up with the currency in the domain name.

The Code:

currency-selector.liquid  

{% assign shopcurrency = shop.permanent_domain %}

<div id="currency-selector">
  <a class="tmb-currency {% if shopcurrency contains 'eu' %}currency_current{% endif %}" href="/"><i class="fa fa-eur"></i></a>
  <a class="tmb-currency {% if shopcurrency contains 'us' %}currency_current{% endif %}" href="/"><i class="fa fa-usd"></i></a>
  <a class="tmb-currency {% if shopcurrency contains 'uk' %}currency_current{% endif %}" href="/"><i class="fa fa-gbp"></i></a>
</div>

Leave a comment