How to create multiple location affiliate site

There are many worldwide stores which have good partner programs. One of well known store is Amazon. Problem is that most of such stores doesn’t provide autodetection of buyer’s location. Instead of this, stores have different domains (example,, So, if you have world wide site, you can lose money if you promote offers for one location. For example, users from Europe don’t like to buy in USA stores, because they must pay additional VAT for each product. How can you solve this? I will show some technics

Update. Now, our theme has inner option for multi currency which is working also with Multi language plugins, like Polylang and WPML. Read how to set Multi currency in Rehub

First of all, you need to have geo ip base and plugin which can detect user country. I tested many plugins and currently I choose GeoIP Detection plugin which is most powerfull as I think. This is because this plugin provides not only shortcodes, but also additional functions for developers. And my favorite functions of plugin is that it has option to add user country and continent to body class. This is very usefull for my tips which I will write now. Also plugin use Maxmind GeoIP Lite City free base and has option to use paid version of base.

Let’s start to do multi location amazon links. You can use such tips also for any shop.

Multi locale dynamic links

One of feature of amazon is that most of products have the same position across all locales. This means that, for example, will be available also in,, etc. So, you need only to check user location and show him correct locale of amazon.

I wrote early, that GeoIP Detection plugin can add class to body tag. Plugin adds two classes, for example, geoip-country-CY and geoip-continent-EU

geoip-country-CY shows country code of user

geoip-continent-EU shows continent code of user

Full list of continents

Code Continent name
AF Africa
AN Antarctica
AS Asia
EU Europe
NA North america
OC Oceania
SA South america

So, for USA, continent class will be geoip-continent-NA

For country code, you can see all codes from Maxmind base page

Now, we can add simple jquery code on your site which will change default domain to domain of country of user.

For example, our main url of offers will be from Now, you want to send all users from Europe to Place such code in your theme

Many themes have field where you can add different scripts, for example, for ads, etc. In my themes, you can place this code in theme option – Analytics/js code

Place in domainforchange your default domain of links. As you see, we use geoip-continent-EU to detect users from Europe and if script find such class, all links which have on your pages will be changed to You can do the same for other continents, just place such peaces of codes

Ok, but what about different countries which have own store locale. For example, it would be bad if you send german users to when they have In this case, you can use country code of GeoIp plugin. So, full code will be

Such code will change links to for europe, and change to for german users or to for users from Spain. Last thing I forgot to add is affiliate ID. Most of multylocation stores use the same affiliate ID for all locations. But Amazon requires separate registration for each locale and you have separate affiliate ID. So, you need to change also a affiliate ID. Code for this will be


Ajax call and links changing

Problem with code above is that it’s working only on current page. But many sites have ajax call of links and content parts, so, you can try to change links on click event. Sometimes can be buggy, but you can try. Code above will have next look

Check one important thing. In first line I used a.re_track_btn, because “re_track_btn” is class in my theme for all affiliate links. Maybe you have another common class for such links. Also, you can try to use just “a” without any class to handle all links, but this is not recommended.

Multiple offers for different localizations

This was easy way to change links. But such method is not universal. Sometimes, you can’t just change domain to get correct links, because offers for different locations have different links and you need to create different offers.

In this case you can use similar plugin GeoTargeting Lite

This plugin has some shortcode to show and hide content to specific countries. For example,

So, you need to create different offers and then wrap each offer for specific country shortcode.

Plugin also supports setting several countries in shortcode

Another way is to use previous plugin but wrap each offer to own div. For this, enable text view of wordpress editor and wrap your offers.


According to such code, your js code will be

Caching issues and how to make cache compatibility geo ip detection

There is one problem with most of plugins. They didn’t support cache, because if you cache page, this page will show the same code to all users and will be static.

But some of cache systems have it’s own Geo Ip extension. One of such system is CloudFlare.

If you use it, you can use it’s geo ip detection instead of Geoip plugins. But you need to add some functions to your theme.

This is code which will do the same as GeoIp detection plugin to add special class to body tag. We will use the same classes, so, other codes which I wrote above will work.

Add such code to functions.php



Facebook page about Online Moneymaking

  1. That’s a great post! Would any of these methods work with Rehub theme+Content Egg plugin? At this moment if I insert the same prduct from 3 different amazon sites (.com and .ca) it would display the one that has the lowest prices as the main one. It would be great if it could just display the price based on users location. Does it make sense?

    • No, this will not work without deep customization. You can disable synchronization with theme Main offer (so, will be no auto selected offer). Then, you can use technics which described here to show correct offer for users inside posts

  2. Thank author!

    I have coupon site ( see demo here -> ) and now I want to expand to Asia.

    In this post, you mean I can install GeoIp Detection, and then copy code in below into functions.php?


    function geoip_classes_add($classes) {

    $country_code = (!empty($_SERVER[“HTTP_CF_IPCOUNTRY”])) ? $_SERVER[“HTTP_CF_IPCOUNTRY”] : ”;
    if ($country_code !=”) {

    $classes[] = ‘geoip-country-‘.$country_code;

    $africa = array(“DZ”,”AO”,”BJ”,”BW”,”BF”,”BI”,”CM”,”CV”,”CF”,”TD”,”KM”,”CG”,”CD”,”CI”,”DJ”,”EG”,”GQ”,”ER”,”ET”,”GA”,”GM”,”GH”,”GN”,”GW”,”KE”,”LS”,”LR”,”LY”,”MG”,”MW”,”ML”,”MR”,”MU”,”YT”,”MA”,”MZ”,”NA”,”NE”,”NG”,”RW”,”RE”,”SH”,”SN”,”SC”,”SL”,”SO”,”ZA”,”SD”,”SZ”,”ST”,”TZ”,”TG”,”TN”,”UG”,”EH”,”ZM”,”ZW”);
    $oceania = array(“AS”,”AQ”,”AU”,”BV”,”IO”,”CX”,”CC”,”CK”,”FJ”,”PF”,”TF”,”GU”,”HM”,”KI”,”MH”,”FM”,”NR”,”NC”,”NZ”,”NU”,”NF”,”MP”,”PW”,”PG”,”PN”,”WS”,”SB”,”GS”,”TK”,”TO”,”TV”,”UM”,”VU”,”WF”);
    $europe = array(“AL”,”AD”,”AT”,”BY”,”BE”,”BA”,”BG”,”HR”,”CY”,”CZ”,”DK”,”DD”,”EE”,”FO”,”FI”,”FR”,”DE”,”GI”,”GR”,”GG”,”HU”,”IS”,”IE”,”IM”,”IT”,”JE”,”LV”,”LI”,”LT”,”LU”,”MK”,”MT”,”FX”,”MD”,”MC”,”ME”,”NL”,”NO”,”PL”,”PT”,”RO”,”RU”,”SM”,”RS”,”CS”,”SK”,”SI”,”ES”,”SJ”,”SE”,”CH”,”UA”,”SU”,”GB”,”VA”,”AX”);
    $asia = array(“AF”,”AM”,”AZ”,”BH”,”BD”,”BT”,”BN”,”KH”,”CN”,”CY”,”GE”,”HK”,”IN”,”ID”,”IR”,”IQ”,”IL”,”JP”,”JO”,”KZ”,”KW”,”KG”,”LA”,”LB”,”MO”,”MY”,”MV”,”MN”,”MM”,”NP”,”NT”,”KP”,”OM”,”PK”,”PS”,”YD”,”PH”,”QA”,”SA”,”SG”,”KR”,”LK”,”SY”,”TW”,”TJ”,”TH”,”TL”,”TR”,”TM”,”AE”,”UZ”,”VN”,”YE”);
    $south_america = array(“AI”,”AG”,”AR”,”AW”,”BS”,”BB”,”BZ”,”BO”,”BR”,”VG”,”KY”,”CL”,”CO”,”CR”,”CU”,”DM”,”DO”,”EC”,”SV”,”FK”,”GF”,”GD”,”GP”,”GT”,”GY”,”HT”,”HN”,”JM”,”MQ”,”MX”,”MS”,”AN”,”NI”,”PA”,”PY”,”PE”,”PR”,”BL”,”KN”,”LC”,”MF”,”VC”,”SR”,”TT”,”TC”,”VI”,”UY”,”VE”);
    $north_america = array(“BM”,”CA”,”GL”,”PM”,”US”);

    if(in_array($country_code, $africa)) {
    $classes[] = ‘geoip-continent-AF’;
    elseif(in_array($country_code, $oceania)) {
    $classes[] = ‘geoip-continent-OC’;
    elseif(in_array($country_code, $europe)) {
    $classes[] = ‘geoip-continent-EU’;
    elseif(in_array($country_code, $asia)) {
    $classes[] = ‘geoip-continent-AS’;
    elseif(in_array($country_code, $south_america)) {
    $classes[] = ‘geoip-continent-SA’;
    elseif(in_array($country_code, $south_america)) {
    $classes[] = ‘geoip-continent-NA’;

    return $classes;

  3. Hi Author,
    I am usng Rehub and tyr to find were to put those code and can’t seem to find Analytics/js code .
    In Theme options- General option , I can see Js code for footer and header….is that were I am suppose to put those code?

  4. Hi! With this method, can i creat price alert for each country ? There are other solutions to do this automatecly ?

    Thanks in advance

  5. Dear,

    My Brazilian clients are redirected to but we want them to go to the where we are affiliates. Does the Code below correct?

    jQuery(document).ready(function($) {
    ‘use strict’;
    var domainforchange = ‘’;

    $(document).on(“click”, “a.re_track_btn”, function(e){
    var $this = $(this);
    var domainforchange = ‘’;

    var linksource = $(this).attr(‘href’);
    if ($(‘body’).hasClass(‘geoip-continent-SA’)) {
    linksource.replace(domainforchange, “”);


    window.location.href= linksource;

    • try to change

      linksource.replace(domainforchange, “”);


  6. Hi,

    First of all thanks for sharing on the internet your knowledge, which is very very useful for some of us.

    That being said, i would like to see if you can help me out achieve what i need to achieve. I know this is quite an old post, but it worth’s giving a shot.

    Im not a programmer, but i know this can be done, I running around the internet looking for a solution, and your post is the closest i could find, but not quite exactly what i need.

    I need a function to be added to functions.php so it uses the Geo Target from Cloudflare to redirect the visitor to a language such as or or for en

    The problem i see is that i need to redirect for example to the spanish version every visitor from Spain, Mexico, Uruguay,etc… As far as my understanding goes, it can be done using HTTP_CF_IPCOUNTRY which is a code that Cloudflare inject in the header, but i have no clue at all how to do so.

    If you could kindly help me out I would very much appreciate it, I could even send you a coffee donation (not kidding, not like I could afford much more ahahahah i haven’t even made a penny yet with my site) on Paypal if you want.

    • It’s too much work. Just use WPML or similar plugins, they have multi language and auto detection of user’s location

  7. Hello Wpsoul,

    Wouldn’t it be easier to just add a dropdown list with country and when you select a country you output a link to your affiliate amazon country ? So the buyer will just have to select his country, and then click on the link..

    If so, before I start programming would you have any idea on how to achieve the most efficient way ?


    • If you use Rehub theme, you can create multilanguage site and you can assign different amazon offers for each language of site. Use plugin WPML for this or similar

Leave a reply

Wordpress optimization, monetizing tips and tricks