Jump to content

Initiating hook when specific package is created


earthgirlllc

Recommended Posts

16 hours ago, earthgirlllc said:

I need to implement a hook on three specific hosting package numbers. How would I go about doing that?

it depends on the hook! 🙂

you're going to have to get the current product IDs - usual place would be from the template using $vars, and then you just use if statements (or in_array if all three result in the hook doing the same thing) to check the value of pid... but as I said, that pid value might be in a different array depending on the template you're working with... it might not even exist and you'll have to get it by using another variable.

Link to comment
Share on other sites

Okay, but what specific hook?  There dozens of them as shown in https://developers.whmcs.com/hooks/hook-index/

Hooks are triggered at different times for different actions.  So you need to pick the hook and come back here and let me know which action you trying to hook in to.

From the sound of it, however, you may want to look at server provisioning modules as that would be package specific and provide the functions needed to do the create, suspend, and terminate for that email account.  If you are already using a module for that and need additional actions, then either the module needs to take care of it or you can use the after or pre module hooks listed in the link above.  Those hooks will provide the package that is being worked on and you can then do the needed actions.

Link to comment
Share on other sites

<?php
add_hook('AfterModuleCreate', 1, function($vars) {
    $packageid = $vars['pid'];
  $Package = WHMCS\Product::find($packageid);
  if ($Package and $Package->id === 5)
  {
     $APi = new externalAPI();
     $API->createAddress("webmaster@".$vars['domain']);
  }
  if ($Package and $Package->id === 1)
  {
     $APi = new blah();
     $API->blahAction();
  }
});

 

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