Jump to content

Set New Clients as Affiliate


vbatra

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.

 

<?php
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);
}
add_hook("ClientAreaRegister",1,"SetAsAffiliate");

 

Link to comment
Share on other sites

This one works.

<?php

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.

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.

Guest
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