How to add a "Your order will be shipped to *your country* tomorrow" dynamically using GEOIP

Highlighted
Tourist
5 0 0

Hi, so I am looking for a way to show my visitor's location (country) and then dynamically tell them when delivery will happen based on what I have implemented for each country.

I already found a way to show the dates, but for the GEOIP, I can't find a way to make it appear. Here's my code now (found in another post):

 

<script>// <![CDATA[
jQuery.ajax({
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function (location) {
jQuery('#country-name').html(location.country_name);
}
});
// ]]></script>

<p>Your order will be shipped to <span id="country-name"></span></p>

 

But it does not show the country.

If someone could help me that would litterally save my life!! Thank you!!

0 Likes
Highlighted
Shopify Partner
100 15 30

Hi,

You can use this:

jQuery.ajax({
	url: '/browsing_context_suggestions.json',
	type: 'get',
	success: function(data){
	  $('#country-name').html(data.detected_values.country_name);
	}
});
0 Likes
Highlighted
Tourist
5 0 0

Hi, Thank you very much for your help. The country name is still not showing unfortunately. Should I save the country name in a variable and then call it? 

0 Likes