Skip to content

Instantly share code, notes, and snippets.

@the-sufi
Last active September 19, 2024 20:05
Show Gist options
  • Save the-sufi/9d1cb013da528e5086ae02883eb2fba1 to your computer and use it in GitHub Desktop.
Save the-sufi/9d1cb013da528e5086ae02883eb2fba1 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' => 'Available Credit',
'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(
'uri' => 'clientarea.php?action=addfunds',
'label' => '<h4 style="text-align:center;">' . $getCurrency['0']->prefix . $client->credit . ' ' . $getCurrency['0']->suffix . '</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>'
);
}
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