Jump to content

Restore the Cancellation Request Sidebar Option on Free Services


Recommended Posts

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.

cancellation request sidebar.png

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!

Link to comment
Share on other sites

  • WHMCS John featured this topic
  • 3 weeks later...

Exactly what I needed! I offer hosting here and there to folks for free (non-profits, churches, etc.) and all I ask is if they ever need to shut it down to let me know so I can process the cancel and clear out the account on the cPanel box, hadn't had a cancel since the recent upgrade, so nice to have a workaround! 

Link to comment
Share on other sites

  • 3 weeks later...

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.

×
×
  • 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