adg273 Posted April 8, 2018 Share Posted April 8, 2018 Hi, I don't do much with PHP and hooks and the like, so please go easy. I want to change a menu item, on the secondary sidebar, in the shopping cart area. I have created a Category - SEO. I want to change where this category points to... my hook is as follows: <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) { $secondarySidebar->getChild('Categories') ->getChild('Search Engine Optimisation (SEO)') ->setUri('https://mydomain.com/seo-packages/'); }); Now if I go straight to the shopping cart, this works and does what I intend it to. However, the moment I go to the client area for example, it craps it and I get the "Oops something went wrong message". What do I do to rectify this? Or can I even do it? MANY THANKS, for anyone who can help me with this. Link to comment Share on other sites More sharing options...
brian! Posted April 9, 2018 Share Posted April 9, 2018 On 4/8/2018 at 22:25, adg273 said: Now if I go straight to the shopping cart, this works and does what I intend it to. However, the moment I go to the client area for example, it craps it and I get the "Oops something went wrong message". the hook itself is more or less there, but you missed out two steps - firstly, you need to get the parent item too (Categories), but secondly, before modifying any navbar/sidebar item, you also need to check that it exists... it will on the intended page and that's why it works there; go to a page where the sidebar doesn't exist, and you're then trying to modify something that doesn't exist and WHMCS will throw a wobbly... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $SecondarySidebar) { if(!is_null($SecondarySidebar->getChild('Categories'))){ $SecondarySidebar->getChild('Categories') ->getChild('Search Engine Optimisation (SEO)') ->setUri('https://mydomain.com/seo-packages/'); } }); Link to comment Share on other sites More sharing options...
adg273 Posted April 9, 2018 Author Share Posted April 9, 2018 Thanks for the reply Brian!. I did that before, but when I did, none of WHMCS worked. When I took ... if(!is_null($SecondarySidebar->getChild('Categories'))){ ...out of the hook, then the cart worked at least. Which is why i'm even more confused. Link to comment Share on other sites More sharing options...
WHMCS Technical Analyst II WHMCS SamP Posted April 10, 2018 WHMCS Technical Analyst II Share Posted April 10, 2018 Hi @adg273! Please try this code - <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 2, function(MenuItem $secondarySidebar) { if (!is_null($secondarySidebar->getChild('Categories'))) { $secondarySidebar->getChild('Categories') ->getChild('Search Engine Optimisation (SEO)') ->setUri('https://mydomain.com/seo-packages/'); } }); Link to comment Share on other sites More sharing options...
brian! Posted April 10, 2018 Share Posted April 10, 2018 On 4/9/2018 at 11:26, adg273 said: I did that before, but when I did, none of WHMCS worked. there was an errant ; in my code which shouldn't have been there... unless it's conflicting with another sidebar hook, either mine or SamP's code should work (they're the same apart from the priority value)... anytime you get a blank screen caused by a hook, enable the "Display Errors" checkbox in setup -> general settings -> others and it should at least give a clue to the cause. also, you'll likely need another hook to change the link in the navbar too... the code would be very similar, except you'd use primaryNavbar instead... and I see you've just figured that out too! Link to comment Share on other sites More sharing options...
adg273 Posted April 10, 2018 Author Share Posted April 10, 2018 Yea, I forgot all about the primary navbar until I finally rectified the secondary sidebar. Thanks for the help lads. Really appreciate it! Link to comment Share on other sites More sharing options...
Recommended Posts