Skip to content

Instantly share code, notes, and snippets.

@mauriciogofas
Last active January 20, 2020 13:28
Show Gist options
  • Save mauriciogofas/8b3c836961fccbe2903894607dc7b051 to your computer and use it in GitHub Desktop.
Save mauriciogofas/8b3c836961fccbe2903894607dc7b051 to your computer and use it in GitHub Desktop.
WHMCS Custom affiliates redirects
<?php
/**
* Custom Affliates Redirects
* © 2017 gofas.net
*
*/
add_hook('AffiliateClickthru', 1, function($vars) {
$affiliate_id = (int)$vars['affiliateId'];
$destination = (string)'https://example.com'; // default destination after affiliate link click
if ( $_REQUEST['page'] ) { // page is the parameter name
$destination = (string)$_REQUEST['page'];
header( "Location: $destination" );
exit;
}
if ( $vars['affiliateId'] === 1 ) { // ID of affiliate
$destination = (string)'https://otherexample.com';
header( "Location: $destination" );
exit;
}
// default destination if not page parameter and not affiliate ID
else {
header( "Location: $destination" );
exit;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment