Jump to content

Sync Due dates for addons to the parent product


cjsmith87

Recommended Posts

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

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