B@SE and JS
Using currency converter - https://dynamicconverter.com/
B@SE and JS
Using currency converter - https://dynamicconverter.com/
| <div class="c-dropdown"> | |
| <form method="post" action="" class="currency_form"> | |
| <input type="hidden" name="ship_country"> | |
| <span>Change currency</span> | |
| <span> | |
| <select style="margin: 3px" name="dc_selected_currency"> | |
| <option value="AUD">AUD Australian Dollar</option> | |
| <option value="NZD">NZD New Zealand Dollar</option> | |
| </select> | |
| </span> | |
| </form> | |
| </div> |
| $(document).ready(function(){ | |
| // For toggling dropdown | |
| $('.c-title') .click(function(){ | |
| $('.currency-wrap').toggleClass('open'); | |
| }); | |
| // Shipping Country Set | |
| var get_country_selected = localStorage.getItem("country_selected"); | |
| if(typeof(get_country_selected)!== "undefined" && typeof(get_country_selected)!== ""){ | |
| $('.currency_form input[name=ship_country]').val(get_country_selected); | |
| } | |
| // Currency Set | |
| var currency = localStorage.getItem('cur') || "AUD"; | |
| changeCurrency(currency); | |
| }); | |
| $(document.body).on('change','.currency-wrap select',function(){ | |
| // Event listener that triggers all the functions | |
| $('.currency-wrap').removeClass('open'); | |
| changeCurrency($(this).val()); | |
| shippingCountryChange($(this).val()); | |
| $('.currency_form').submit(); | |
| }); | |
| function changeCurrency(currency) { | |
| // Cosmetic flag image change | |
| if (currency == 'AUD') { | |
| $('.c-title').html("<img src='[%ntheme_asset%]img/aud-flag.png[%END ntheme_asset%]'/> $ AUD"); | |
| } else if(currency == 'NZD') { | |
| $('.c-title').html("<img src='[%ntheme_asset%]img/nzd-flag.png[%END ntheme_asset%]'/> $ NZD"); | |
| } | |
| } | |
| function shippingCountryChange(country) { | |
| // Sets shipping country in local storage | |
| if (country == 'NZD'){ | |
| var country_selected = 'NZ'; | |
| }else{ | |
| var country_selected = 'AU'; | |
| } | |
| $('.currency_form input[name=ship_country]').val(country_selected); | |
| localStorage.setItem("country_selected",country_selected); | |
| } |