Jump to content

Issuing Credits When New Account Is Created


Shay Mei

Recommended Posts

5 hours ago, Shay Mei said:

Is there any way to auto issue credits when a new client creates an account via WHMCS?

not from the admin settings and off-hand, I can't think of an existing addon that can do it.

ultimately, if you're not bothered about issuing an add funds invoice for the credit, you could use a ClientAdd action hook to add $20 to their account when it's being created - that means that as soon as the client logs in, they will be able to use the $20.

of course, by default WHMCS doesn't usually show them their credit balance in the client area (though it will at checkout), so you might also need to use sentq's credit sidebar hook too.

if you only use one currency on your site, e.g USD, then that's a simple hook; if it's a multi-currency site, then that gets a little more complicated as you've have to calculate the $20 deposit in the client's chosen currency and add that amount instead.

Link to comment
Share on other sites

On 8/1/2019 at 9:53 PM, brian! said:

not from the admin settings and off-hand, I can't think of an existing addon that can do it.

ultimately, if you're not bothered about issuing an add funds invoice for the credit, you could use a ClientAdd action hook to add $20 to their account when it's being created - that means that as soon as the client logs in, they will be able to use the $20.

of course, by default WHMCS doesn't usually show them their credit balance in the client area (though it will at checkout), so you might also need to use sentq's credit sidebar hook too.

if you only use one currency on your site, e.g USD, then that's a simple hook; if it's a multi-currency site, then that gets a little more complicated as you've have to calculate the $20 deposit in the client's chosen currency and add that amount instead.

Thank you Brian. It's exactly what I was looking for! :D

Link to comment
Share on other sites

On 06/08/2019 at 10:09, Shay Mei said:

^^" I noticed that it's written in php, which I have zero experience with. Which variable should I hook? Could you give me an example of the code?

so to "preload" a new account upon creation with a credit balance of 20 (in the client's chosen currency) is a simple hook...

<?php

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

	$client = \WHMCS\User\Client::find($vars['userid']);
	if ($client) {
		$client->credit = 20;
		$client->save();
	}
});

so if there is only one currency in your WHMCS, e.g USD, then this will give them a $20 credit balance; if you have multiple currencies, and they choose EUR as their currency, this will give them a €20 credit balance - remember that once a client has chosen a currency, they cannot change it... and if they've made an order, you shouldn't change their currency for them either.

btw - another way to do this would be to use promotional codes - e.g a code that a user can only use once, only at signup and only for specific products... if you can do that, then it avoids using the above hook... either way, you're deducting $20 (or €20 etc) from their invoice.

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