MYGSG - Nicholas S Posted June 23, 2019 Share Posted June 23, 2019 Hi WHMCS Community, I am trying to display a WHMCS Client Account Number using a hook, I have the basic code as below: <?php use WHMCS\View\Menu\Item; use Illuminate\Database\Capsule\Manager as Capsule; add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) { $client = Menu::context( "client" ); $fieldid = Capsule::table('tblcustomfields')->where('fieldname', 'Account Number')->where('type', 'client')->value('id'); $fieldvalue = Capsule::table('tblcustomfieldsvalues')->where('fieldid', $fieldid)->where('relid', $client->id)->value('value'); $bodyhtml = '<p>Your Account Number is '{$client_code}'.</p>'; $examplePanel = $homePagePanels->addChild( 'Account Number', array( 'label' => Lang::trans('Account Number'), 'icon' => 'fa-example', 'extras' => array( 'color' => 'red', 'btn-link' => '#', 'btn-text' => Lang::trans('Account Number'), 'btn-icon' => 'fa-plus', ), 'bodyHtml' => $bodyhtml <p>{$client_code}</p> )); }); However, nothing displays in the client area. Any help with this would be appreciated. Kindest Regards, Nicholas Tae-Soo Sansom – Company Executive OfficerRoot Layer Technologies, The Gardens, Unit 9A, 204 Alice Street, Brisbane, QLD 4000 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 23, 2019 Share Posted June 23, 2019 (edited) You had syntax error. Here's the fixed version. <?php use WHMCS\View\Menu\Item; use Illuminate\Database\Capsule\Manager as Capsule; add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) { $client = Menu::context( "client" ); $fieldid = Capsule::table('tblcustomfields')->where('fieldname', 'Account Number')->where('type', 'client')->value('id'); $fieldvalue = Capsule::table('tblcustomfieldsvalues')->where('fieldid', $fieldid)->where('relid', $client->id)->value('value'); $bodyhtml = '<p>Your Account Number is ' . $client_code . '</p>'; $examplePanel = $homePagePanels->addChild( 'Account Number', array( 'label' => Lang::trans('Account Number'), 'icon' => 'fa-example', 'extras' => array( 'color' => 'red', 'btn-link' => '#', 'btn-text' => Lang::trans('Account Number'), 'btn-icon' => 'fa-plus', ), 'bodyHtml' => $bodyhtml . '<p>' . $client_code . '</p>', )); }); Edited June 23, 2019 by Kian 0 Quote Link to comment Share on other sites More sharing options...
MYGSG - Nicholas S Posted June 23, 2019 Author Share Posted June 23, 2019 Hi @Kian, Thanks for that, it's perfect and now displays: However, it does not display the actual account number. Any ideas? Just so you know it works from: https://infinitycds.co.za/whmcs-module2/whmcs-account-number/ Kindest Regards, Nicholas Tae-Soo Sansom – Company Executive OfficerRoot Layer Technologies, The Gardens, Unit 9A, 204 Alice Street, Brisbane, QLD 4000 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 23, 2019 Share Posted June 23, 2019 Your Laravel query is not correct. The following one will work. <?php use WHMCS\View\Menu\Item; use Illuminate\Database\Capsule\Manager as Capsule; add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) { // Replace with the ID of your Client Custom Field $FieldID = '1'; $Data = Capsule::select(Capsule::raw('SELECT t2.value FROM tblcustomfields AS t1 LEFT JOIN tblcustomfieldsvalues AS t2 ON t1.id = t2.fieldid WHERE t2.relid = "' . $_SESSION['uid'] . '" AND t1.id = "' . $FieldID . '"')); $FieldValue = $Data[0]->value; $bodyhtml = '<p>Your Account Number is ' . $FieldValue . '</p>'; $examplePanel = $homePagePanels->addChild( 'Account Number', array( 'label' => Lang::trans('Account Number'), 'icon' => 'fa-example', 'extras' => array( 'color' => 'red', 'btn-link' => '#', 'btn-text' => Lang::trans('Account Number'), 'btn-icon' => 'fa-plus', ), 'bodyHtml' => $bodyhtml . '<p>' . $FieldValue . '</p>', )); }); Notice that you need to change $FieldID with the ID of your Client Custom Field. You should avoid basing your query on field names. What if next year you decide to rename "Account Number" in as "Client Number"? IDs never change therefore use them. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 23, 2019 Share Posted June 23, 2019 fundamentally, the Capsule query is fine - but the limitation that Kian mentions is perfectly true and that i'd also suggest using IDs... the problem for you really centred that you were trying to output a variable that you hadn't defined... and was therefore empty... also, in recent versions, that FA icon wouldn't exist... nor can I particularly understand the reason for the + Account Number link top right if its not actually going to do anything... <?php use WHMCS\View\Menu\Item; use WHMCS\Database\Capsule; add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) { $client = Menu::context( "client" ); $fieldid = Capsule::table('tblcustomfields')->where('fieldname', 'Account Number')->where('type', 'client')->value('id'); $fieldvalue = Capsule::table('tblcustomfieldsvalues')->where('fieldid', $fieldid)->where('relid', $client->id)->value('value'); $bodyhtml = '<p>Your Account Number is '.$fieldvalue.'.</p>'; $examplePanel = $homePagePanels->addChild( 'Account Number', array( 'label' => Lang::trans('Account Number'), 'icon' => 'fa-user', 'bodyHtml' => $bodyhtml )); }); 0 Quote Link to comment Share on other sites More sharing options...
MYGSG - Nicholas S Posted June 23, 2019 Author Share Posted June 23, 2019 Hi @brian! and @Kian, Thanks, both for your input, I get what you are both saying and Brian, I was just using a default hook template to test my functionality before doing anything like styling etc. I have tried the above code to make this work, however, I still seem to get to output of the Client Account Number. Am I doing something incorrectly here? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 23, 2019 Share Posted June 23, 2019 (edited) 4 minutes ago, RLT - Nicholas said: I have tried the above code to make this work, however, I still seem to get to output of the Client Account Number. Am I doing something incorrectly here? do you mean that it's not outputting the actual account number in the output ? are you sure that the value is stored as a Client Custom Field and not somewhere else in the database ? Edited June 23, 2019 by brian! 0 Quote Link to comment Share on other sites More sharing options...
MYGSG - Nicholas S Posted June 23, 2019 Author Share Posted June 23, 2019 Just now, brian! said: do you mean that it's not outputting the actual account number in the output ? are you sure that the value is stored as a Client Custom Field and not somewhere else in the database ? Correct, I see no output in where I would expect to see the Account Number display. According to the the module "addon" developer, it should be viable anywhere within WHMCS. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 23, 2019 Share Posted June 23, 2019 1 minute ago, RLT - Nicholas said: Correct, I see no output in where I would expect to see the Account Number display. According to the the module "addon" developer, it should be viable anywhere within WHMCS. if it's a Client Custom Field, then when you click on the Profile Tab in the Client Summary in the admin area, you should see the value ENGE02 (or whatever your equivalent Account Number value is) in one of the existing ustom fields... if it's not there, then it must be being stored elsewhere. 0 Quote Link to comment Share on other sites More sharing options...
MYGSG - Nicholas S Posted June 23, 2019 Author Share Posted June 23, 2019 8 minutes ago, brian! said: if it's a Client Custom Field, then when you click on the Profile Tab in the Client Summary in the admin area, you should see the value ENGE02 (or whatever your equivalent Account Number value is) in one of the existing ustom fields... if it's not there, then it must be being stored elsewhere. Hi @brian!, You can see it's like this: However the field appears empty. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 23, 2019 Share Posted June 23, 2019 (edited) 8 minutes ago, RLT - Nicholas said: However the field appears empty. two thoughts... did you install this account number addon *after* you had created this test account in WHMCS ? I don't know, but the implication from that module page you linked to, is that when a client account is created, a custom account number is created automatically... but if the test account was created *before* the addon was installed, then maybe the account number generation process hasn't occurred... You might need to go back to the developers to that, but frankly what I would do is manually enter a value into that "CLIENTCODE" customfield and see what happens.... or if you don't want to do that, find another client account that actually has a value in CLIENTCODE and use them to test the panel output. importantly - you're going to have to change that hook and tweak the reference of 'Account Number' to 'CLIENTCODE' in the code and see if doing both those things fix your situation. Edited June 23, 2019 by brian! 0 Quote Link to comment Share on other sites More sharing options...
MYGSG - Nicholas S Posted June 24, 2019 Author Share Posted June 24, 2019 Hey brian!, I am waiting on the developer to update me as even adding a numerical value to the field "CLIENTCODE" did not display anything I even tested this feature with a whole new account setup twice. I shall keep you updated and thanks for all your help. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.