Search code examples
phpsqlbillingwhmcs

How to add credit by default in WHMCS


How can I add default credit in WHMCS?

I mean when a user signup with WHMCS, they will receive some predefined credit balance in their account (credits can be used to purchase products)

I did search but didn't get any result.


Solution

  • You could use WHMCS hook system together with the API. I haven't tested this code, but it should work more or less out of the box.

    Create a file in includes/hooks/

    add_hook('ClientAreaRegister', 1, function($vars) {
        $command = "addcredit";
        $adminuser = "admin";
        $values["clientid"] = $vars['userid];
        $values["description"] = "Adding credits via ClientAreaRegister hook";
        $values["amount"] = "40.00";
    
        $results = localAPI($command,$values,$adminuser);
    });
    

    Make sure you have a user "admin" or create a new user and change above code to match.

    References: https://developers.whmcs.com/hooks-reference/client-area-interface/#clientarearegister http://docs.whmcs.com/API:Add_Credit