Add a Special Offer Panel

A promotional sidebar panel in the Client Area

Sidebars help provide context or additional information for the main content of the page. Different pages in the Client Area may have different sidebar items.

If you want to offer a special promotion (for example, for an anniversary, celebration, holiday, or partner deal), you can add a panel with all of the relevant information.

For more information, see Client Area Sidebars.

This example uses the ClientAreaPrimarySidebar hook and the menu item’s getFirstChild() and setBodyHtml() methods. To add panel with links to the sidebar we must:

  1. Get the first panel from the primary sidebar.
  2. Set the panel’s body HTML.

Create the includes/hooks/specialOfferInSidebar.php file in your WHMCS installation using the example below. As with the previous example the new file and hook within the file is run on page load and adds the image and link to the topmost panel in the primary sidebar, no matter which page the client is accessing.

Example Code

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) {
    // The HTML for the link to the special offer.
    $specialOfferHtml = <<<EOT
    <a href="//myawesomecompany.com/special-offer/">
       <img src="/assets/img/catdeals.png" alt="Click here for amazing deals!">
       Kitten says <strong><em>thanks</em></strong> for making us the best web host!
    </a>
EOT;

    if ($primarySidebar->count() > 0) {

        // Add a link to the special offer to the first panel's body HTML. It will render
        // above the panel's menu item list.
        $firstSidebar = $primarySidebar->getFirstChild();

        $firstSidebar->setBodyHtml($specialOfferHtml);

    }
});

Last modified: November 12, 2024