Jump to content

New customers as Affiliates automatically


tangogc

Recommended Posts

 
I would like to automatically set new customers as affiliates in WHMCS without needing them to do it manually.
 
i'm trying to use this hook with whmcs 8.0.4 but some advice doesn't work?

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

Edited by tangogc
Link to comment
Share on other sites

2 minutes ago, tangogc said:

i'm trying to use this hook with whmcs 8.0.4 but some advice doesn't work?

that's one of Kian's hooks...

https://github.com/Katamaze/WHMCS-Action-Hook-Factory/blob/master/hooks/NewClientsAsAffiliates.php

I suppose in v8+, the results line of code should be...

$results = localAPI('AffiliateActivate', array('userid' => $vars['client_id']), $adminUsername);

... though personally I wouldn't use the adminusername part.

35 minutes ago, tangogc said:

I would like to automatically set new customers as affiliates in WHMCS without needing them to do it manually.

bear in mind that this hook only runs when a new client registers via the registration page - if they register via making an order,e.g via the cart, then this won't run... I would have thought using the ClientAdd hook point instead of ClientAreaRegister would cover both options.

Link to comment
Share on other sites

I have modified in this way , could work ?

 

<?php

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

Link to comment
Share on other sites

nearly - you should only need to change the add_hook line...

add_hook('ClientAreaRegister', 1, function($vars)

to...

add_hook('ClientAdd', 1, function($vars)

the other lines should remain the same - and you will need to use $vars['client_id'] rather than $vars['user_id'] because the AffiliateActivate API expects a client ID value to be passed to it and not a user ID.

Link to comment
Share on other sites

12 minutes ago, brian! said:

nearly - you should only need to change the add_hook line...


add_hook('ClientAreaRegister', 1, function($vars)

to...


add_hook('ClientAdd', 1, function($vars)

the other lines should remain the same - and you will need to use $vars['client_id'] rather than $vars['user_id'] because the AffiliateActivate API expects a client ID value to be passed to it and not a user ID.

here reworked based on your suggestion, is it correct ?

 

<?php

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

Link to comment
Share on other sites

are you suggesting me to remove this line ?

$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

 

<?php

add_hook('ClientAdd', 1, function($vars)
{
       $results = localAPI('AffiliateActivate', array('userid' => $vars['client_id']), $adminUsername);
});

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