Automatically detect a buyer's country (for multiple currency support)

Getting Started


You may be looking to offer multi-currency support for your Celery pre-orders. The method below would be the only way to do this seamlessly with caveats.

1. You need a separate Celery account for each currency.
2. A developer is required.

Use a free web service

You will need to submit an AJAX POST request to http://freegeoip.net/json. Once you receive the buyer's location information, you will update the page or redirect to a new one with the correct country.

Here is how you submit your request for location information:

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script >
  $.ajax({
    url: 'https://freegeoip.net/json/',
    type: 'POST',
    dataType: 'jsonp',
    success: function(location) {
       var country_code = location.country_code;

       // DO SOMETHING EWITH COUNTRY CODE
    }
  }); 
  </script>

Country codes are in ISO format. Learn more about ISO formatting.

Redirect to another Celery shop

If you have a special store for your international customers, you can redirect to it from your US store using the following code.

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
$.ajax({ 
  url: 'https://freegeoip.net/json/'
  type: 'POST'
  dataType: 'jsonp',
  success: function(location) {
    // If the visitor is browsing from Canada.
    if (location.country_code === 'CA') {
      // Redirect visitor to the Canada store.
      window.location.href = 'http://www.trycelery.com/shop/canada_store';
    }
  }
} );

Rotate Celery Shop Slugs

Alternatively, you may want to trigger a country specific checkout depending on a buyer's location.

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$.ajax({ 
  url: 'https://freegeoip.net/json/'
  type: 'POST'
  dataType: 'jsonp',
  success: function(location) {
    // If the visitor is browsing from Canada.
    if (location.country_code === 'CA') {
      $("div.button-container") .html("<button data-celery='canada_store' data-celery-version='v2'>Pre-Order</button>");
    }
  }
} );
</script>
<div class="button-container"></div>


Feedback and Knowledge Base