Jump to content
Sign in to follow this  
WHMCS Josh

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!

Share this post


Link to post
Share on other sites

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! 

Share this post


Link to post
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.

Sign in to follow this  

  • Similar Content

    • By Danse
      Hi, does anyone has a Hook which auto enables the DNS of new Domains in WHMCS? 
      Customers always complaining that DNS Management is missing and i have to switch that on, all the Time. 
      And i wont take this as upselling position. So activate DNS Management in Frontend for "0$" is aswell not suitable for me. 
      It just be there and done 🙂
      Any Suggestions, or Code Templates? 
    • By hosthuski
      Hello all. I am hoping you can help me do what I think should be simple for people who have dealt with hooks already.
      I want to do this:
      IF a product's ID = x (I imagine this involves getting the product ID from a variable and doing an IF statement in PHP)
      THEN 
      get the service_domain field (built-in field, not custom field),
      run a shell script while passing the domain field as a bash variable to be used within the script's execution.
      Why do I want to do this?
      This will allow me to begin the process of provisioning maintenance coverage via WP CLI for customers who order a maintenance plan from us.
      I'll create an additional 2 hooks -- three total so one for each maintenance plan. If I can get the first hook, i can make the others and likely merge them together. I just need a "template" to follow from someone who understands PHP more than on the surface like I do. This ultimately will chain 3 of my servers together. WHMCS server, our cPanel server, and the maintenance server.
      Any help is appreciated. Would anyone be willing to paste in an effective code sample that I can use?
    • By Dreza
      Hello,
      I created a hook file for the 'OrderPaid' event and it seems like the $vars variable that is being passed to it always comes up empty. Does anyone know why this is happening?
    • By Dreza
      Hello,
      I created a hook file for one of my addon modules and it seems like the hook event is always happening. The hook event is 'OrderPaid'.
      When I look at the module logs there is an entry for this hook event every minute even though no orders have been paid for during this time.
      I need to know why this is happening. If anyone can help me I would appreciate it.
    • By GagalKoding
      Hi there,
      I have returned $vars from EmailPreSend Hooks like this
      Array ( [messagename] => Other Product/Service Welcome Email [relid] => 805 [mergefields] => Array ( [service_first_payment_amount] => WHMCS\View\Formatter\Price Object ( [price:protected] => 350000 [currency:protected] => Array ( [id] => 1 [code] => IDR [prefix] => Rp [suffix] => IDR [format] => 3 [rate] => 1.00000 ) [defaultFormat:protected] => {PREFIX}{PRICE}{SUFFIX} [defaultCurrencyDescriptor:protected] => Array ( [format] => 1 [prefix] => [suffix] => ) ) How to print "350000" on price protected object from ['mergefields']['service_first_payment_amount']
      I try $vars['mergefields']['service_first_payment_amount']->price;
      But i get message Error: Cannot access protected property WHMCS\View\Formatter\Price::$price
  • 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