Skip to content

Instantly share code, notes, and snippets.

@jwieder
Last active July 4, 2021 08:32
Show Gist options
  • Save jwieder/3d470a4e85e041ca41bc2cee0c5aa7a8 to your computer and use it in GitHub Desktop.
Save jwieder/3d470a4e85e041ca41bc2cee0c5aa7a8 to your computer and use it in GitHub Desktop.
Place this hook script in the includes/hooks/ directory of the WHMCS folder within your server's webroot to display each client's available credit balance as a sidebar item within the WHMCS Client Area homepage and billing-related pages. Created by combining elements from two scripts from the WHMCS forums and fixing several issues with both. Tes…
<?php
/**
* Display Client's Credit Balance as a Sidebar Item in Client Area Homepage and Billing-related Pages
*
* @author Josh Wieder
* @link https://gist.github.com/jwieder/3d470a4e85e041ca41bc2cee0c5aa7a8#file-creditbalancesidebar-php
* @since WHMCS v6.0.0+
*/
use WHMCS\View\Menu\Item as MenuItem;
# Add Balance To Sidebar
add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $primarySidebar){
$filename = APP::getCurrentFileName();
$client = Menu::context("client");
$clientid = intval( $client->id );
$action = $_GET['action'];
$allowed = array('invoices', 'quotes', 'masspay', 'addfunds');
/* prevents balance display to unauth'd users */
if ($filename!=='clientarea' || $clientid===0 || strpos($_SERVER['REQUEST_URI'], 'verificationId') !== false || is_null($client)) {
return;
}
/*
* uncomment this to hide the sidebar if the client has no balance
* if ($client->credit <= 0.00) { return; } */
$primarySidebar->addChild('Client-Balance', array(
'label' => Lang::trans('availcreditbal'),
'uri' => '#',
'order' => '1',
'icon' => 'fa-money'
));
# Get Currency
$getCurrency = getCurrency($clientid);
$balanceDisplay = formatCurrency($client->credit, $getCurrency);
# Retrieve the panel we just created.
$balancePanel = $primarySidebar->getChild('Client-Balance');
// Move the panel to the end of the sorting order so it's always displayed
// as the last panel in the sidebar.
$balancePanel->moveToBack();
$balancePanel->setOrder(0);
# Add Balance.
$balancePanel->addChild('balance-amount', array(
'uri' => 'clientarea.php?action=addfunds',
'label' => '<h4 style="text-align:center;">'.$balanceDisplay.'</h4>',
'order' => 1
));
$balancePanel->setFooterHtml(
'<a href="clientarea.php?action=addfunds" class="btn btn-success btn-sm btn-block">
<i class="fa fa-plus"></i> Add Funds </a>'
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment