John.Helyar Posted May 8, 2017 Share Posted May 8, 2017 Hi there Hope you can help I'm currently in the process of building our new site and having a bit of a problem with using Hooks I'm trying to adjust the Sidebar menu on the order forms so under Categories where it lists the items I'm trying to use Hooks to change the URL to go somewhere else. Also under the actions bit, I was trying to hide the Domain Renewals section I'm using the below code to do this <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function($secondarySidebar) { $secondarySidebar->getChild('Categories') ->getChild('Web Hosting') ->setUri('https://www.domain-name.uk/webhosting'); }); add_hook('ClientAreaSecondarySidebar', 1, function($secondarySidebar) { $secondarySidebar->getChild('Categories') ->getChild('Reseller Hosting') ->setUri('https://www.domain-name.uk/reseller-hosting'); }); Now, this does what I want it to do with no problem but when I go to the client area the page is blank it won't load if I remove the file from the Hooks folder the client area loads fine. I have found a few different ways of doing it but I haven't had any luck and I hope that someone can shed some light on it as I have run out of ideas or if there is a better way of doing this without using hooks maybe I look forward to your reply. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 8, 2017 Share Posted May 8, 2017 Hi John, your problem is caused by the hook code not checking whether the sidebar exists before trying to modify it - so that's why it will work fine in the cart (where it does exist), and fails elsewhere (where it doesn't). so the quick solution is to check that the parent sidebar exists before trying to modify it... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function($secondarySidebar) { if (!is_null($secondarySidebar->getChild('Categories'))) { $secondarySidebar->getChild('Categories') ->getChild('Web Hosting') ->setUri('https://www.domain-name.uk/webhosting'); $secondarySidebar->getChild('Categories') ->getChild('Reseller Hosting') ->setUri('https://www.domain-name.uk/reseller-hosting'); } }); the only way the above hook should fail would be if either of the product groups got renamed or deleted - you could code the hook to get around that if you had to, but it complicates it... so simplest solution is to remember to modify the hook if you change either of these product group names! 0 Quote Link to comment Share on other sites More sharing options...
John.Helyar Posted May 8, 2017 Author Share Posted May 8, 2017 Ok I have just tried this and its working fine been able to hide the Product Addons now as well without it breaking so thank you very much for your help was on it for a while last night just couldn't get my head around it So again thank you for 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.