Jump to content

Activate all clients as affiliates


madbutcher
Go to solution Solved by SimpleSonic,

Recommended Posts

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'
        ]);
    }
});

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

  • Solution
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]);
    }
});

 

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