Jump to content

account number generate hook

Recommended Posts

Hello Everyone.

hope all are fine. can someone help me to modify this code a little so i can achieved what i am looking for.

basically i have hook file for a client custom field. what the hook does is when i create a new customer its create a random 8 digit number for the custom field Account Number.

its fine until now but the problem is

1. This hook doesn't check the existing value in the database , so there is chance to create the duplicate account number and we cant allocate same account for two customer.

2. once the Account created and we have the account number then any admin or staff can modify the client details form and easily change the account number. and this is another dangerous point.

we cant change the account number for any customer. once we create the customer we will have permanent account number for that customer.

so what can i do in this case with this hook? i have given the code in here.

thanks again in advance




use Carbon\Carbon;
if (!defined("WHMCS"))
    die("This file cannot be accessed directly");

function AccountNumber($vars) {
    $userid = $vars['userid'];
    $command = 'UpdateClient';
    $values = array(
        'clientid' =>  $userid,
        'customfields' => base64_encode(serialize(['Account Number'=>rand(11111111,99999999)]))
    $results = localAPI($command, $values);
    if ($results['result'] == 'success') {
        logActivity('Success :  Customer ID set successfully to User # '.$userid);
    } else {
        logActivity('Error :  Customer ID could not be set to User # '.$userid.'. Response : '.$results['result']);



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.

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.

  • 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