Jump to content

Help with Hooks


cesiumdeth

Recommended Posts

I am trying to get hooks working. As a test I've created a file called myhooks.php and placed it in the /includes/hooks folder (same location as the WHMCS included hooks example file named example.php). In this file I've created a hook that should fire when an admin changes an invoice to either "Cancelled" or "Unpaid" status. To prove the hook is being called I'm trying to make an internal API call to make an entry in the activity log. I log in with my admin account (for my example we'll say my username is "cesiumdeth"), navigate to an invoice, and change the status back and forth between a status of "Cancelled" and "Unpaid" and save between each change of course. In the whmcs Activity Log I get the default log entry that notes "Modified Invoice Options - Invoice ID: 12345", but I do not see the custom log entry from the call in my code. Anyone see what I'm missing or messed up and why this isn't working? By the way the I've checked that the admin user I'm using in the code does have API permissions (it is a full administrator account with all permissions).

 

The code in my "myhooks.php" file is as follows:

<?php
function wr_hook_InvoiceChange($vars)
{
   $command = "logactivity";
   $adminuser = "cesiumdeth";
   $values["description"] = "proof wr_hook_InvoiceChange was called";

   $results = localAPI($command,$values,$adminuser);
}
add_hook("InvoiceUnpaid",1,"wr_hook_InvoiceChange");
add_hook("InvoiceCancelled",1,"wr_hook_InvoiceChange");

?>

Link to comment
Share on other sites

  • 3 weeks later...

With the help of WHMCS support I was able to figure this out. There was nothing wrong with my hook code. The problem is the InvoiceUnpaid and InvoiceCancelled hooks only fire when an admin clicks the "Mark Unpaid" or "Mark Cancelled" button while viewing an invoice. Personally I think this is a deficiency of these hook points because there are multiple ways you can set the status of an invoice to "Unpaid" or "Cancelled" (such as the sequence I described in my original post that was not firing the hooks). I also let WHMCS support know that the hook documentation for these two hook points mentions nothing about this limitation. I'm posting this hoping it helps someone find this answer faster until the WHMCS hook documentation is updated.

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