Sanora Dev Posted September 9, 2022 Share Posted September 9, 2022 Hello everyone, I'm searching for a way to assign specific products that can use credits and products that can't. for example, if a customer has credit he or she can use it for all hosting plans, but not for google cloud plans. Is there a hook that i can use for this or maybe a third party addon? I've search and googled for days now, but couldn't find anything about it. The only thing i found is an old topic that wanted (in general) the same as what i'm looking for. Old topic: Thanks, Elias 0 Quote Link to comment Share on other sites More sharing options...
Remitur Posted September 10, 2022 Share Posted September 10, 2022 There're two cases where you need to check this: during renewal invoice creation When a renewal invoice is issued, if there's available credit WHMCS will automatically apply to it in client area, when the user can select an unpaid invoice and decide to apply credit to it The second one, I guess, it's quite easy: just modify the involved .tpl with some kind of IF clause The first one is a little more complicated: here the code of a hook that prevent automatic credit application to new invoices if the credit is not sufficient to full pay the invoice: // // remove applied credit to invoices, when credit applied is not sufficient to fully pay // function remove_credit_from_new_invoice($vars) { if ($vars['status']=="Paid") { return; } $postData=array('invoiceid' => $vars['invoiceid'], ); $invoicedata = localAPI('GetInvoice', $postData); if ( $invoicedata['credit'] != 0 AND $invoicedata['balance'] != 0 ) { $postData = array( 'invoiceid' => $vars['invoiceid'], 'amount' => - $invoicedata['credit'], ); $res = localAPI('ApplyCredit', $postData); logactivity('Insufficient credit removed by hook: invoice id# '.$vars['invoiceid'].' - credit removed '.$invoicedata['credit'],$vars['user']); } } add_hook('InvoiceCreationPreEmail', 5, "remove_credit_from_new_invoice" ); You need to modify it in order to: check the kind of service billed set the status of the invoice back to "unpaid" if it was fully paid with credit Hope this will be helpful to you. 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted September 20, 2022 Share Posted September 20, 2022 follow 😉 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.