Question

i am building an affiliate site using woo commerce and wp affiliates. There will be a network of 20-30 affiliate sites linking back to main site.

I need to display the logo/banner of the referring site on the main site. So if a user is referred from Widget Maker 1 website to the main site i need to display Widget Maker 1 logo or banner at the top. Same for Widget Maker 2, if a different user is referred from widget maker 2 website to the main site i need to display widget maker 2 logo or banner.

Since using query strings in the url for affiliate links this seems like it would be pretty trivial to do but i am at a lose of where to start.

Anyone have any experience doing this sort of thing?

Was it helpful?

Solution

The solution for this is, in my opinion, divided into two steps.

The first step is to set the variable, which defines the affiliate, that sends you the visitor.

The second step is to display an appropriate logo based on the value of the first variable.

The solution for the first step would probably look somewhat like this:

if( isset($_GET['affiliate']) ){
    $affiliate_value = $_REQUEST['affiliate'];
    setcookie('affiliate', $affiliate_value, time()+3600);
} elseif( isset($_COOKIE['affiliate']) ){
    $affiliate_value = $_COOKIE['affiliate'];
} else {
    $affiliate_value = NULL;
}

This would probably go somewhere into the functions.php. What this does is to look into the url query string (for the purpose of demonstration the query variable is called "affiliate") and if a value is there we assign a variable and save that value in a cookie.

If no query string is there we look for a cookie. If nothing is there the value is NULL.

Then, after you have defined your $affiliate_valuewe can build a switch in the header.php to display the correct logo. It should look somewhat like this:

switch($affiliate_value) {
    case("affiliate_one"):
        echo '<img src="url_to_logo_one" >';
        break;
    case("affiliate_two"):
        echo '<img src="url_to_logo_two" >';
        break;
    case("affiliate_three"):
        echo '<img src="url_to_logo_three" >';
        break;
    default:
        echo '<img src="url_to_default_logo" >';
        break;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top