Welio Posted February 1, 2017 Share Posted February 1, 2017 Hello, I have put the hook with the code below in the directory /includes/hooks/: ------------------------------------------------------------------ <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { $urlidr = $vars['clientsdetails']['customfields15']; if (!is_null($primaryNavbar->getChild('Services'))&&!is_null($urlidr)) { $primaryNavbar->getChild('Services') ->addChild('Emergency Contacts', array( 'label' => Lang::trans('buyResellerWebsite'), 'uri' => $systemurl.'cart.php?a=add&pid='.$urlidr, 'order' => '100', )); } }); ------------------------------------------------------------------ The issue is that the variable $urlidr = $vars['clientsdetails']['customfields15'] remains empty, even though listed among those in the page with {debug} in the file clientareahome.tpl. Anyone can help me, please? Thanks. Link to comment Share on other sites More sharing options...
brian! Posted February 1, 2017 Share Posted February 1, 2017 if you know the variable exists in Smarty, then you can do this... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { GLOBAL $smarty; $urlidr = $smarty->getVariable('clientsdetails')->value['customfields15']; if (!is_null($primaryNavbar->getChild('Services'))&&!is_null($urlidr)) { $primaryNavbar->getChild('Services') ->addChild('Emergency Contacts', array( 'label' => Lang::trans('buyResellerWebsite'), 'uri' => $systemurl.'cart.php?a=add&pid='.$urlidr, 'order' => '100', )); } }); i'm not sure you need $systemurl in the link, but i've left it in. Link to comment Share on other sites More sharing options...
Welio Posted February 1, 2017 Author Share Posted February 1, 2017 Thanks a lot Brian, I was going crazy. It works fine (just with $systemurl). Link to comment Share on other sites More sharing options...
themangeary Posted January 30, 2018 Share Posted January 30, 2018 Hi, Could you help with this please. I am trying to add a custom field to this code below but it does not work, i get this on the Hook = ('clientsdetails')->value['customfields5']; and the php error Notice: Undefined property: WHMCS\Smarty::$getVariable in /home2/public_html/shop/vendor/smarty/smarty/libs/Smarty.class.php on line 738 This is the code <?php use WHMCS\View\Menu\Item; add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) { GLOBAL $smarty; $thankYouMessage = <<<EOT $urlidr = $smarty->getVariable('clientsdetails')->value['customfields5']; <p>Thanks for beta testing our latest offerings! To show our appreciation we'd like to provide next month of service <strong>on the house</strong>.</p> EOT; // Add a homepage panel with a link to a free month promo and mode it to the // front of the panel list. $homePagePanels->addChild('thanks', array( 'label' => 'Thanks for the help!', 'icon' => 'fa-thumbs-up', 'order' => 20, 'extras' => array( 'color' => 'gold', 'btn-link' => 'https://www.parcelmonitor.com', 'btn-text' => 'Redeem Your Free Month', 'btn-icon' => 'fa-arrow-right', ), 'bodyHtml' => $thankYouMessage, 'footerHtml' => 'Act fast! This offer expires soon!', )); }); Link to comment Share on other sites More sharing options...
sentq Posted January 31, 2018 Share Posted January 31, 2018 in smarty the function called "getTemplateVars" $smarty->getTemplateVars('foo'); but if what you want is to get client details, then use the Context instead: $client = Menu::context('client'); Link to comment Share on other sites More sharing options...
themangeary Posted January 31, 2018 Share Posted January 31, 2018 I added that code as below but i still do not get the client detials only this = ('clientsdetails')->value['customfields5']; <?php use WHMCS\View\Menu\Item; add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) { $client = Menu::context('client'); $thankYouMessage = <<<EOT $urlidr = $smarty->getVariable('clientsdetails')->value['customfields5']; <p>Beta testing this section <strong>more to follow</strong>.</p> EOT; // Add a homepage panel with a link to a free month promo and mode it to the // front of the panel list. $homePagePanels->addChild('thanks', array( 'label' => 'Thankyou for your order!', 'icon' => 'fa-thumbs-up', 'order' => 20, 'extras' => array( 'color' => 'gold', 'btn-link' => 'https://www.parcelmonitor.com', 'btn-text' => 'Track your Box', 'btn-icon' => 'fa-arrow-right', ), 'bodyHtml' => $thankYouMessage, 'footerHtml' => 'Being updated now!', )); }); Link to comment Share on other sites More sharing options...
sentq Posted January 31, 2018 Share Posted January 31, 2018 replace {put-custom-field-id-here} with the custom field id in the code below and it should give you the right value: <?php use WHMCS\View\Menu\Item; use WHMCS\Database\Capsule; add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) { $client = Menu::context('client'); $getcustomfield = Capsule::table("tblcustomfieldsvalues") ->join('tblcustomfields', 'tblcustomfield.id', '=', 'tblcustomfieldsvalues.fieldid') ->where('tblcustomfields.id', "=", "{put-custom-field-id-here}") ->where('tblcustomfieldsvalues.relid', '=', $client->id) ->select('tblcustomfieldsvalues.value') ->first(); $urlidr = $getcustomfield->value; $thankYouMessage = <<<EOT $urlidr <p>Beta testing this section <strong>more to follow</strong>.</p> EOT; // Add a homepage panel with a link to a free month promo and mode it to the // front of the panel list. $homePagePanels->addChild('thanks', array( 'label' => 'Thankyou for your order!', 'icon' => 'fa-thumbs-up', 'order' => 20, 'extras' => array( 'color' => 'gold', 'btn-link' => 'https://www.parcelmonitor.com', 'btn-text' => 'Track your Box', 'btn-icon' => 'fa-arrow-right', ), 'bodyHtml' => $thankYouMessage, 'footerHtml' => 'Being updated now!', )); }); Link to comment Share on other sites More sharing options...
Recommended Posts