Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vikassaini01/80808375fc3a65f1a605a6fedc5a282c to your computer and use it in GitHub Desktop.
Save vikassaini01/80808375fc3a65f1a605a6fedc5a282c to your computer and use it in GitHub Desktop.
WHMCS Show Credit Balance on side panel/sidebar
<?php
/**
* code goes inside "includes/hooks" directory
*/
//for customizing nav menu items
use WHMCS\View\Menu\Item as MenuItem;
//for interacting with DB
use Illuminate\Database\Capsule\Manager as Capsule;
/**
* Show Credit Balance on side panel/sidebar
* @param MenuItem $primarySidebar
*/
function dctit_show_available_credit_balance_sidebar (MenuItem $primarySidebar) {
$filename = basename($_SERVER['REQUEST_URI'], ".php");
$parseFile = explode('.', $filename);
$client = Menu::context("client");
$clientid = intval($client->id);
if ($parseFile['0'] !== 'clientarea' || $clientid === 0) return;
if ( $client->credit <= 0 ) return;
$primarySidebar->addChild('Client-Balance', array(
'label' => 'Credit Balance',
'uri' => '#',
'order' => '1',
'icon' => 'far fa-money-bill'
));
# Get Currency
$getCurrency = Capsule::table('tblcurrencies')->where('id', $client->currency)->get();
# 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(
'label' => '<div style="margin: 10px; font-size: 20px;color: #369;" align="center">' . $getCurrency['0']->prefix . $client->credit . ' ' . $getCurrency['0']->suffix . '</div>',
'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>'
);
}
add_hook('ClientAreaPrimarySidebar', 1, 'dctit_show_available_credit_balance_sidebar');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment