Display custom product information based on user's IP Location

Hi all,

I want to add under my ATC button to evey product, “?Delivery in 1-3 working days”, with the goal of improving conversions etc.
As I ship internationally, this is only true of local deliveries.

Does anyone know how to add an IF statement that the text displays purely based on IP Location?
What would be maybe even better would be: “delivered by the XX of August 2021” (calculated based on today’s date +2), and again the “+2” is a variable based on location.. so Germany = +2, Europe = +5, rest of world = +10

thanks for the advise and help!

Hi @Alex080 ,

I’m commenting here because I’m in the same situation as you are, but I might have a bit more info for you. I just need someone to help me bridge the gaps so I can use variables from my first script into my second one.

  1. to determine the user location I used ipinfo.io. Take a look at this: https://ipinfo.io/json
    I am personally using my own ipinfo.io token to access their API (50K free monthly requests), and you would only need to know the country, so yours would look like this:

You would need to replace $TOKEN by your own token from the ipinfo.io website.

  1. to display dates for shipping delays, I am currently using this:
Get it between  **-** 
                            {{ '//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js' | script_tag }}
                      		

It looks like this:

M0w45_0-1630530367720.png

This works well, but I need to manually adjust the fromDate and toDate for min and max shipping days.

I now have to create a loop so that:

  • if my user is from Canada (I’ll know the country based on script #1) my fromDay and toDay will be 1 and 3 (between 2 and 4 business days to ship there),
  • if my user is from the US, my fromDay and toDay will be 2 and 6
  • if my user is from Europe, my fromDay and toDay will be 6 and 12

But this is where I’m stuck, as I’m not sure how I can use my variables from script #1 in my script #2
Even though this does not answer your question, I hope this will help, or that someone will find this thread and help us complete our scripts :).

Cheers!

I want to display products based on a IP address. Some companies do not want us to show their prices or products online, but we use Shopify for all online and instore purchases. We would like to control what is show to our static IP address to customers in the store but they would not be displayed to other customers and google across the internet. If you have any advise I would appreciate it.

I’m replying to this thread even though it’s quite old, because it seems to be still getting views and I didn’t find any similar questions on the forums that had a solution. Hope it helps someone.

  1. First you will need to sign up for a service that looks up location based on the IP address. There are quite a few of these and you can find them by Googling “IP geolocation.”
  2. Then you will need to reference their documentation to see how to run an IP lookup using javascript. @M0w45 gave an example using ipinfo.io.
  3. Then get the country
  4. Then make an if statement that will modify the text depending on the location.
  5. Add the div/paragraph/heading etc that the javascript is modifying to your template in the place where you want it to appear. In this example, you would make sure that you have 1 div on your product page template that has id=“location-based-message”.
  6. Add the javascript and style to a custom liquid section somewhere in the page template. You could put it at the bottom of the page as the last section in the template.

Here’s an example using ipapi.com. Where I have the Germany example, you can add more options. You can also use if/else.

I’m setting the div that contains the text to display: none (ie, it’s invisible) to start out with, so that the text will only show up after the javascript has had a chance to run and determine what text should be displayed.

.location-message { display: none; }
Default message