Jump to content

Set New Clients as Affiliate

Recommended Posts

I am out of touch from WHMCS development for more than a year.

I want to set all the newly signed up clients as an affiliate in WHCMS and created the following hook. The following code is saved as SetAsAffiliate.php in hooks directory. I assume that the code should run whenever there is a new client registration but it is not happening. Can someone please tell what am I missing? TIA.


if (!defined("WHMCS"))
    die("This file cannot be accessed directly");

function SetAsAffiliate($vars) {
$clientid = $vars['userid'];
//Set the API parameter and vars
    $command = 'AffiliateActivate';
	$values["user"] = $clientid;
$results = localAPI($command, $values);


Share this post

Link to post
Share on other sites

This one works.


add_hook('ClientAreaRegister', 1, function($vars)
    $adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later
    $results = localAPI('AffiliateActivate', array('userid' => $vars['userid']), $adminUsername);

Keep in mind that ClientAreaRegister hook point triggers only when customers register from register.php page. That means that if they're registering from cart.php while placing an order they are not activated as affiliates. Use ClientAdd if you want to activate them independently from what page they're registering.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.


Important Information

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