Jump to content

Editing secondary sidebar screws everything up


adg273

Recommended Posts

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

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

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

  • WHMCS Technical Analyst II

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

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...

QMQw1PB.png

the code would be very similar, except you'd use primaryNavbar instead... and I see you've just figured that out too! :idea:

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated