Is it possible to have a visitors redirected to different pricing page based on their IP address? One for USA and another for UK?

I’m trying to create a pricing page that would show prices based on the user’s IP address. This is not part of Wix stores so the regular apps aren’t suitable. I’m not a web developer but tried to research a bit. I understand that I have to use Wix Router function along an external get IP function and finally redirect with Wix location? Please help, I wish I could explain better. Thank you.

1 Like

I tried different approach, as I couldn’t figure out how to use Wix Router (I couldn’t find enough and good sources about it); It is not optimal but it works.

  1. I created two separate e-stores (for two different countries).

  2. The first e-store is created under the subdomain “country1 . mymaindomain . com”. It has the same products but with different prices. Sometimes, it has different promotions as well.

  3. The second e-store is created under the subdomain “country2 . mymaindomain . com”. It has the same products but with different prices. Sometimes, it has different promotions as well.

  4. I created a Landing-Page with my logo and a welcome message. My main domain is linked to this Landing-Page. So, when people from any country type “mymaindomain . com” they will be taken by DNS to my Landing-Page.

  5. Then, I used the following code in the Landing-Page “masterPage . js” section to automatically identify the location where the visitors are coming from and redirect them to the correct website accordingly.

// The code in this file will load on every page of your site
import wixLocation from 'wix-location';
import {fetch} from 'wix-fetch';
$w.onReady(function () {

// Fetch the user's location details
fetch('https://extreme-ip-lookup. com/json', {
method: 'get'
})

// Check if the request was successful
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
}
})

.then((json) => {
// Set the user's countryCode as a const
const loc = json . countryCode;

// Check if location is from country1
//You have to replace "country1 with the (Internet country domains list (TLDs)) for country country1
if(loc === "country1" ){
// Redirect to  WebSite1
wixLocation . to ("https://country1 . mymaindomain . com");
}

// Check if location is from country2
//You have to replace "country2 with the (Internet country domains list (TLDs)) for country country2
if(loc === "country2" ){
// Redirect to  WebSite2
wixLocation . to ("https://country1 . mymaindomain . com");
}

});

});

I hope this will help…

1 Like

Hey! Thank you so much for answering. I’m going to try this out and see how it works.

Hey Jose, did you try code, is it work? I’m looking for a solution for the same need. Thanks.

Hey, I want to thank you once again. Back then when you first answered my query I was very confused as I wasn’t proficient with Velo Code, now I came across an article and learned to do this. When I came looking for this post, I realized that you had given the right answer all along.

Thank you.

Hey, the code above is absolutely perfect! I didn’t get it back then but now I do and it is also implemented on my website .

If you visit the URL www.josesibik.com/pricing from India, you’ll be redirected to a pricing page with the amounts in INR or else you’ll stay on the page with USD.

I even wrote an article about it here .