Jump to content

WHMCS - Hook points


nuxwin

Recommended Posts

Hello ;

 

I'm the developer of the KaziWhmcs plugin which provides a WHMCS server provisioning module for our control panel (i-MSCP).

 

Because our control panel is using the product domain names as username, I need to override the usernames which are auto-generated by WHMCS when a new order is placed (created), whatever the context (as from the client area or from the admin area). Indeed, right now, the usernames, which are derived from the domain names, are truncated to 8 letters max and some characters such as the dot are automatically discarded by the WHMCS username validator/generator (It's only an assumption made on the current behavior here since I've not access to the source code).

 

Thus, I've searched for an event allowing me to operate at post-creation of the orders but unfortunately, no hooks point is provided for such thing. Indeed, I've found the following interesting hook points:

 

PendingOrder From the Order page in the Admin area, clicking on the Pending Order button or via the API command. As the order is being set to Pending, before any updates are

completed.

 

The problem here is that any listener registered on this event is triggered only when the status of the order is set back to "pending". This event doesn't seem to be triggered after a new order creation (when the initial status is set to "pending"). For me this appears like an inconsistent behavior, and it would be interesting to trigger that event also on post order creation, when the initial status is set to "pending".

 

Anyway this event seem to be triggered only in admin/API contexts, not from any action coming from the client (through the client area)

 

ShoppingCartCheckoutCompletePage As the cart complete page is displayed to the client.

 

This event allow my listener to do the expected job but unfortunately, it is is only triggered from the client area context when the checkout is made.

 

_________________

 

Finally, I've "figured out" with the following listener which listen to the "OverrideOrderNumberGeneration" event. Indeed, this event is triggered in every contexts. It's really a workaround here because this event is triggered on pre-order creation and thus, at this state, I don't know the orderid yet:

 

**
* Update auto-generated usernames with product domain names
*
* @param array $vars Variables
* @return void
*/
function hook_imscp_update_username($vars)
{
   if (!empty($vars['products'])) {
       register_shutdown_function(
           function ($products) {
               foreach ($products as $product) {
                   if (isset($product['domain'])) {
                       update_query(
                           'tblhosting',
                           array(
                               'username' => $product['domain'],
                               'lastupdate' => 'now()'
                           ),
                           array(
                               'domain' => $product['domain']
                           )
                       );
                   }
               }
           },
           $vars['products']
       );
   }
}

add_hook('OverrideOrderNumberGeneration', 1, 'hook_imscp_update_username');

 

As you can see here, I uses this listener to register a shutdown function which is responsible to override the username for each product once the new order is placed (created). This not really a beautiful piece of code but this works.

 

My recommendations

 

It would be nice to have some generical events triggered at some points (in every contexts) such as:

 

PreCreateOrder

PostCreateOrder

...

 

Here I'm talking about the order process but this advises apply to all hook categories.

 

Thank you for reading me.

 

BTW: I'm using the "event" and "listener" terms here because it's more accurate to my eyes than using the hook function and hook point terms.

Edited by nuxwin
Typo
Link to comment
Share on other sites

Edit. It could be great if a nice admin lifts some restrictions on my account:

 

- I'm unable to post without approval (Should be solved)

- I'm unable to send any private message (even to an WHMCS admin) (Solved)

- I'm unable to edit my profile (Solved)

 

 

Thanks you ;)

 

- - - Updated - - -

 

I'm also unable to edit my post... It's a shame ;) (Solved)

Edited by nuxwin
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