In the latest release, you may have noticed that the Request Cancellation link in the left sidebar has been removed for free and one time products and services.
This change was made in response to a bug report relating to one time products not being automatically cancelled. There was some concern that allowing cancellation requests for free and one time items, which have no next due date, and therefore terminate immediately on the following cron run could lead to irrevocable data loss.
It is important to note that this is only a visual change that removes the link to submit a cancellation request. Submitting a cancellation request for a free service is still possible. If you wish to restore the option to cancel free products, you can do so using a hook.
I've prepared some sample code that uses the ClientAreaPrimarySidebar hook point to achieve this.
Here is the code below:
<?php
/**
* This hook restores the Request Cancellation sidebar option on free services
*
* @author WHMCS Josh
* @see https://developers.whmcs.com/hooks-reference/client-area-interface/#clientareaprimarysidebar
* @see https://developers.whmcs.com/advanced/db-interaction/
*/
use WHMCS\Database\Capsule;
use WHMCS\View\Menu\Item;
add_hook('ClientAreaPrimarySidebar', 1, function($primarySidebar) {
// Get the handle for the Service Details Overview sidebar
$serviceDetailsOverview = $primarySidebar->getChild('Service Details Overview');
// Make sure the handle is not null
if (!is_null($serviceDetailsOverview)) {
// Make sure the ID is available
if (!empty($_REQUEST['id'])) {
$serviceId = (int) $_REQUEST['id'];
// Check if this is a free service
$billingCycle = Capsule::table('tblhosting')
->where('id', $serviceId)
->value('billingcycle');
if ($billingCycle === 'Free Account') {
// Add the cancellation request menu item for the service to the sidebar
$serviceDetailsOverview->addChild(
'freeServiceCancellationRequest',
[
'name' => 'CancellationRequest',
'label' => 'Request Cancellation',
'uri' => '/clientarea.php?action=cancel&id=' . $serviceId,
'order' => 90,
]
);
}
}
}
});
To install this, you can simply add the code to a file in your /includes/hooks directory such as /includes/hooks/free_product_cancellation_request.php.
For convenience, I've attached the completed hook file to this post here: free_product_cancellation_requests.php
Below is also a screenshot of how this looked on my test installation of WHMCS 7.7.0.
Please note that this is being provided only as an example and is not guaranteed to work with future versions of WHMCS.
Feel free to modify it to suit your needs and I hope it helps!