madbutcher Posted October 21, 2023 Share Posted October 21, 2023 Hello, I want to activate all existing clients as affiliates and to automatically activate as affiliate every new client. Do you have any suggestions how I can achieve this? Thank you in advance. 0 Quote Link to comment Share on other sites More sharing options...
SimpleSonic Posted October 23, 2023 Share Posted October 23, 2023 Here is an example hook to enable affiliate status for new clients: <?php use WHMCS\Database\Capsule; add_hook('ClientAdd', 1, function($vars) { $clientID = $vars['userid']; // Check if the client is already an affiliate. $affiliateData = Capsule::table('tblaffiliates')->where('clientid', $clientID)->first(); if (!$affiliateData) { // If not an affiliate, enable affiliate status for this client. Capsule::table('tblaffiliates')->insert([ 'clientid' => $clientID, 'date' => date('Y-m-d'), 'status' => 'Active' ]); } }); 1 Quote Link to comment Share on other sites More sharing options...
madbutcher Posted October 25, 2023 Author Share Posted October 25, 2023 On 10/23/2023 at 8:41 PM, SimpleSonic said: Here is an example hook to enable affiliate status for new clients: <?php use WHMCS\Database\Capsule; add_hook('ClientAdd', 1, function($vars) { $clientID = $vars['userid']; // Check if the client is already an affiliate. $affiliateData = Capsule::table('tblaffiliates')->where('clientid', $clientID)->first(); if (!$affiliateData) { // If not an affiliate, enable affiliate status for this client. Capsule::table('tblaffiliates')->insert([ 'clientid' => $clientID, 'date' => date('Y-m-d'), 'status' => 'Active' ]); } }); Hello, Thank you for your help. Unfortunately it doesn't work for me for some reason. 0 Quote Link to comment Share on other sites More sharing options...
Solution SimpleSonic Posted October 25, 2023 Solution Share Posted October 25, 2023 9 hours ago, madbutcher said: Hello, Thank you for your help. Unfortunately it doesn't work for me for some reason. Sorry about that. I have tested the following and it works to enable affiliate when a new client registers: <?php use WHMCS\Database\Capsule; add_hook('ClientAdd', 1, function($vars) { $clientID = $vars['userid']; // Check if the client is already an affiliate. $affiliateData = Capsule::table('tblaffiliates')->where('clientid', $clientID)->first(); if (!$affiliateData) { // Use WHMCS API to enable affiliate status for the client. localAPI('AffiliateActivate', ['userid' => $clientID]); } }); 0 Quote Link to comment Share on other sites More sharing options...
madbutcher Posted October 25, 2023 Author Share Posted October 25, 2023 Hi, This one works great, thank you! 0 Quote Link to comment Share on other sites More sharing options...
SimpleSonic Posted October 25, 2023 Share Posted October 25, 2023 54 minutes ago, madbutcher said: Hi, This one works great, thank you! You're welcome! 0 Quote Link to comment Share on other sites More sharing options...
CMS911 Posted October 30, 2023 Share Posted October 30, 2023 Sorry for asking an obvious question but where do you put that code? In a specific template file? 0 Quote Link to comment Share on other sites More sharing options...
SimpleSonic Posted October 30, 2023 Share Posted October 30, 2023 28 minutes ago, CMS911 said: Sorry for asking an obvious question but where do you put that code? In a specific template file? Create a PHP file named "auto_affiliate.php" and place that code in the file and then move the file to the folder: includes/hooks/ 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.