Jump to content

using affiliate system with referral codes not cookies


Recommended Posts


 I am using WHMCS as back end billing for selling an online service.. however i wish to be able to let clients gain affiliate/referral  payments by simply being able to tell the next tier client as " promotion code " not "use a cookie  on a website " as listed in the standard affilate documentation i read, as none of these existing clients would have a website of any kind.. ..  Promotion codes dont seem to  linked to  affiliate payments   from what i read....?

 Could anyone shed light whether this way of gaining  multi tier clients with an affiliate "code" be able to be implemented.. or do i just  need new glasses to read the docs with ? :)


Link to comment
Share on other sites

WHMCS cannot help you with that but you can make it with an action hook. First of all navigate to Setup > Custom Client Field and create a custom field named Affiliation Code (field type must be Text Box). Tick Show on Order Form. Once finished you have to note down the ID of the field you've just created. You can get the ID by inspecting the Delete button. You'll find something like this:

<a href="#" onclick="doDelete('15');return false" class="btn btn-danger btn-xs">Delete Field</a>

In my case 15 is the ID we're looking for. Now let's move to the action hook. Create a php file in includes/hooks. You can name it as you want. Please notice that I used somePrefix_ twice in the code. You should rename it with something else to avoid any possible function name collision.

Now focus on Configuration area. $affiliationFieldID should be equal to 15 (the ID of our Custom Client Field). Below you have to add all your partners. They key of $partners must be the ID of your partner and the value must be their affiliation code. Let me explain.

$partners['40'] = 'DOG'; 

When a client registers on your website and he insert "DOG" in the Affiiation Code, he automatically receives the affiliation cookie of your Affiliate/Client with ID 40.


use WHMCS\Cookie;
use WHMCS\Database\Capsule;

function somePrefix_ClientAdd($vars)
    // Configuration
    $affiliationFieldID         = 15; // ID of Client Custom Field for Affiliation Code
    $partners['39']             = 'CAT'; // Affiliation code of partner/client ID 39
    $partners['40']             = 'DOG'; // Affiliation code of partner/client ID 40
    $partners['41']             = 'YEP'; // Affiliation code of partner/client ID 41
    $partners['42']             = 'SAD'; // Affiliation code of partner/client ID 42
    // Do not edit below this line
    if (in_array($vars['customfields'][$affiliationFieldID], $partners))
        $affID = Capsule::table('tblaffiliates')->where('clientid', array_search($vars['customfields'][$affiliationFieldID], $partners))->first(['id']);
        header('Location: *?aff=' . $affID->id . '&gocart=true');

add_hook('ClientAdd', 1, 'somePrefix_ClientAdd');

In conclusion your Affiliate/Client with ID 40 simply have to say to his/her referred visitor «Register on example.com and don't forget insert DOG in the Affiliation Code field on the registration form». No URLs involved. Of course the code can be improved since for example it "dog" (lowercase) will not work.

Edited by Kian
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated