james-a
11/21/2017 - 11:52 AM

Geo Currency

<script>
jQuery.ajax( { 
  url: '//freegeoip.net/json/', 
  type: 'POST', 
  dataType: 'jsonp',
  success: function(location) {
    // If the visitor is browsing from UK.
    if (location.country_code === 'GB') {
      	$("#currencies").val("GBP");
    	$("#currencies").change();
    }
    // If the visitor is browsing from US.
    else if(location.country_code === 'US'){
      	$("#currencies").val("USD");
    	$("#currencies").change();
    }
    // If the visitor is browsing from Canada.
    else if(location.country_code === 'CA'){
      	$("#currencies").val("CAD");
    	$("#currencies").change();
    }
    // If the visitor is browsing from Australia.
    else if(location.country_code === 'AU'){
      	$("#currencies").val("AUD");
    	$("#currencies").change();
    }
    // If the visitor is browsing from Canada.
    else if(location.country_code === 'CA'){
      	$("#currencies").val("CAD");
    	$("#currencies").change();
    }
    // If the visitor is browsing from Europe.
     else if( location.country_code === 'AT' || location.country_code === 'BE' || location.country_code === 'CY' || location.country_code === 'CZ' || location.country_code === 'DE' || location.country_code === 'DK' || location.country_code === 'EE' || location.country_code === 'ES' || location.country_code === 'FI' || location.country_code === 'FR' || location.country_code === 'GR' || location.country_code === 'HU' || location.country_code === 'IE' || location.country_code === 'NO' || location.country_code === 'NL' || location.country_code === 'PO' || location.country_code === 'SE' ){

     	$("#currencies").val("EUR");
    	$("#currencies").change();
    }
    // switch to USD by default
    else{
 		$("#currencies").val("USD");
    	$("#currencies").change();
    }
  }
} );
</script>