javascript (Shopify)根据客户的地理位置自动更改商店的货币

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript (Shopify)根据客户的地理位置自动更改商店的货币相关的知识,希望对你有一定的参考价值。

// Dependencies
// - https://github.com/carolineschnapp/currencies

// Don't change currency if Cookie has been already set
if (Currency.cookie.read() == null) {

jQuery.ajax( {
  url: '//freegeoip.net/json/',
  type: 'GET',
  dataType: 'jsonp',
  success: function(location) {
    if (location.country_code == 'TH') { // Default shop currency
      $('[name=currencies][value=THB]').attr('checked', 'checked');
    } else if (location.country_code == 'JP') { // Secondary currency
      $('[name=currencies][value=JPY]').attr('checked', 'checked');
    } else { // Fallback currency
      $('[name=currencies][value=USD]').attr('checked', 'checked');
    }
    // Let the scripts in 'currencies.liquid' handle the rest
    $('[name=currencies]').change();
  }
} );

}

// Based upon code by Ben Klinger (www.studiove.com)
// Source: https://ecommerce.shopify.com/c/shopify-discussion/t/auto-change-currency-based-on-location-tutorial-179134

以上是关于javascript (Shopify)根据客户的地理位置自动更改商店的货币的主要内容,如果未能解决你的问题,请参考以下文章