Add a Panel to Specific Pages
On this page
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.
- You might want to add a sidebar panel to list contact information, like the hours and information for your support department.
- You can add this as a panel that only displays on relevant pages, like the page for submitting support tickets.
For more information, see Client Area Sidebars.
Add a Panel to a Specific Page
This example uses the ClientAreaPrimarySidebar
hook and the Menu
item’s addChild()
, moveToFront()
, and setBodyHtml()
methods to add the new panel. The special message to the user addresses the logged in user by first name using the Menu::context()
method and the client
object’s firstName
property:
- Determine if the user is visiting
submitticket.php
. - Add a
Support Hours
panel to the primary sidebar and move it to the front so it displays at the top. - Create child items in the support hours panel saying when support is open and closed.
- Determine if support is currently open.
- If there is a user logged in then determine their first name.
- Assign the support hours’ panel body HTML to a special message depending on the logged in user’s first name and whether support is currently open.
Create the includes/hooks/addSupportHours.php
file in your WHMCS installation using the example below. This hook file is picked up on page load and adds the custom panel and message to the primary sidebar before the submit ticket page renders.
Example Code
<?php
use Carbon\Carbon;
use WHMCS\View\Menu\Item as MenuItem;
// Add a helpful support hours notice to the top of the sidebar on the submit
// ticket page.
if (App::getCurrentFilename() == 'submitticket') {
add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) {
// Create the support hours panel and make sure it's the first one
// displayed.
/** @var MenuItem $supportHours */
$supportHours = $primarySidebar->addChild('Support Hours');
$supportHours->moveToFront();
// Add hours to the panel.
$supportHours->addChild(
'<strong>Open</strong> 08:00-17:00 M-F',
array(
'icon' => 'far fa-smile',
'order' => 1,
)
);
$supportHours->addChild(
'<strong>Closed</strong> Weekends',
array(
'icon' => 'far fa-frown',
'order' => 2,
)
);
// Add a custom notice to the support hours panel with the logged in
// client's first name and a different message depending on whether
// support is open.
/** @var \WHMCS\User\Client $client */
$client = Menu::context('client');
$greeting = is_null($client)
? ''
: ", <strong>{$client->firstName}</strong>";
$now = Carbon::now();
$supportIsOpen = $now->isWeekday()
&& $now->hour >= 8
&& $now->hour <= 17;
$supportHours->setBodyHtml(
$supportIsOpen
? "Hi{$greeting}! We're open and will respond to your ticket soon!"
: "Don't worry{$greeting}! We will respond on the next business day. Sit tight!"
);
});
}
Last modified: October 30, 2024