cjsmith87 Posted April 2, 2019 Share Posted April 2, 2019 Hi, We have a "Web Connector" addon to one of our product that needs to be an addon, not a configuration option, as we need it to have its own licence key and to be active as soon as we accept the order. I know this isnt possible within WHMCS so i am trying to use hooks to override what gets created. So far I have worked out i can override the price in the basket using the following: add_hook('OrderAddonPricingOverride', 1, function($vars) { $return = []; if (!array_key_exists('proddata', $vars)) { /** * This is an addon only purchase for existing service */ $serviceData = Service::find($vars['serviceid']); if ($serviceData && $vars['addonid'] == 3 && $serviceData->packageId == 2) { } } return $return; }); Inside the IF I will need to use the $serviceData to calculate the new price from the next due date of the service. I dont think i can set the next due date here as it seems to only accept recurring and setup. Another option I have looked at is: add_hook('CartTotalAdjustment', 1, function($vars) { $cart_adjustments = array(); if (sizeof($vars['products']) > 0) { } elseif (array_key_exists('addons',$vars)) { $serviceData = Service::find($vars['addons'][0]['productid']); print($serviceData->nextduedate); $cart_adjustments = [ "description" => "Partial Subscription", "amount" => "-18.00", "taxed" => false, ]; } return $cart_adjustments; }); to deduct the relevant amount from the order, which is great because it also shows on the invoice. The only problem with this is that the invoice has the wrong dates on the product line e.g. Addon (######) - <Product Name> (02/04/2019 - 01/04/2020) * Also, the next due date is wrong as it runs for a year from the date it is created where as I want it to finish on the same date as the main service. I think I can use: add_hook('AfterShoppingCartCheckout', 1, function($vars) { print_r($vars); }); to update the values directly in the database but is this the best way to do it? It seems like a bit of a hack for something that you would expect to be built into a billing system 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.