tangogc Posted January 16, 2021 Share Posted January 16, 2021 (edited) 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 January 16, 2021 by tangogc 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 16, 2021 Share Posted January 16, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
tangogc Posted January 16, 2021 Author Share Posted January 16, 2021 thanks Brian I confirm you are great as usual could you show me how modify to have both function working please ? in my site 99% of registration are via Cart thanks 0 Quote Link to comment Share on other sites More sharing options...
tangogc Posted January 16, 2021 Author Share Posted January 16, 2021 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); }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 16, 2021 Share Posted January 16, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
tangogc Posted January 16, 2021 Author Share Posted January 16, 2021 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); }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 16, 2021 Share Posted January 16, 2021 5 minutes ago, tangogc said: here reworked based on your suggestion, is it correct ? yes - I just tried it without the adminUsername parts and it works fine in v8.0.4 0 Quote Link to comment Share on other sites More sharing options...
tangogc Posted January 16, 2021 Author Share Posted January 16, 2021 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); }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 16, 2021 Share Posted January 16, 2021 <?php add_hook('ClientAdd', 1, function($vars) { $results = localAPI('AffiliateActivate', array('userid' => $vars['client_id'])); }); 1 Quote Link to comment Share on other sites More sharing options...
tangogc Posted January 16, 2021 Author Share Posted January 16, 2021 thanks 0 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.