Jump to content

Using Hook to add sidebar menu item in navbar!


Recommended Posts

Hello, 

I am trying to remove sidebar items and add them to navbar especially on the products page. I want to remove categories and action menu from the sidebar and add them to the navbar. 

I have tried to do this using hooks, but I am unable to do so. I failed to understand how to work with hooks.
I need your help in understanding how to use hooks. I have already created a hook file inside include/hooks directory, and have written the function in this file. Is this all we have to done to use a hook or is there something I am missing. Also, Do we have to call a hook function somewhere inside the code?

please help!

thanks,

Link to comment
Share on other sites

You will get results on the first couple of links. Goto DDG and search for: site:whmcs.community sidebar hook or click here: https://duckduckgo.com/?q=site%3Awhmcs.community+sidebar+hook

Basically, you want to create a file named w/e you want in the root/includes/hooks folder (at root directory of whmcs install) and pop into that .php file... something from one of the search engine results.

Did you visit or read this doc yet? https://docs.whmcs.com/Client_Area_Navigation_Menus_Cheatsheet

That cheatsheet is kinda helpful, but the hooks on the forums are way more nice. here is a hook, for example that will remove sidebar on knowledgebase page

<?php

use WHMCS\View\Menu\Item as MenuItem;
 
add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{

    if (!is_null($primarySidebar->getChild('Support Knowledgebase Categories'))) {
                 $primarySidebar->removeChild('Support Knowledgebase Categories');
    }

});

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
    if (!is_null($secondarySidebar->getChild('Support Knowledgebase Tag Cloud'))) {
                 $secondarySidebar->removeChild('Support Knowledgebase Tag Cloud');
    }

    if (!is_null($secondarySidebar->getChild('Support'))) {
                 $secondarySidebar->removeChild('Support');
    }
});

 

Link to comment
Share on other sites

6 hours ago, IamAQ said:

I am trying to remove sidebar items and add them to navbar especially on the products page. I want to remove categories and action menu from the sidebar and add them to the navbar. 

other than a link to view cart, doesn't your site already do that ?

PuavCUY.png

 

6 hours ago, IamAQ said:

I have tried to do this using hooks, but I am unable to do so. I failed to understand how to work with hooks.

you can remove those two sidebars with a hook, that's simple...

<?php

use WHMCS\View\Menu\Item as MenuItem;
 
add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
    if (!is_null($secondarySidebar->getChild('Categories'))) {
                $secondarySidebar->removeChild('Categories');
    }

    if (!is_null($secondarySidebar->getChild('Actions'))) {
                $secondarySidebar->removeChild('Actions');
    }
	
    if (!is_null($secondarySidebar->getChild('Choose Currency'))) {
                $secondarySidebar->removeChild('Choose Currency');
    }	

});

... but the cart won't automatically adjust its width - so you'll be left with an empty space where the sidebar was (it's been like that since v6 was launched 3 years ago)...

fFH9YKq.png

... and the only way to fix that is by editing the template... and if you're going to do that, there's no point using a hook in the first place!

you may need to be more specific about what exactly you want to do...

as an aside, and I don't think this is relevant to your situation, but I went searching for it because I knew I had posted a solution where you could move sidebars to navbars... and as it took ages to find, i'll post a link so that it's easier for others to find.

i'd checked it on v7.7.1 and the idea still works... thanks.png

W2dUcaC.png

Link to comment
Share on other sites

10 hours ago, brian! said:

other than a link to view cart, doesn't your site already do that ?

 

Yes, you are right that's why I want to remove them from the sidebar. It is useless having the same options twice on the page.
 

Link to comment
Share on other sites

10 hours ago, brian! said:

you can remove those two sidebars with a hook, that's simple...



 

I prefer not to use hooks if at the end I need to editing template too.
But I want to know who to use a hook, Is there a need to call hook function? Or it gets loaded automatically. 
I know we creat hook file inside include/hooks directory. Can we name hook file whatever we want? Or it must be specified, Also Is they get load automatically when the page loads? Or we have to call that hook function in our templates code, where we want to make changes.?

Link to comment
Share on other sites

I have read this topic earlier and is useful, And It is the one that got me in trouble 😜  as I tried to use hook and fails to understand how to add this on the required page. I have added the hook file but nothing changes. I know it is no longer needed in my case but I want to know what I was missing. 

Link to comment
Share on other sites

6 hours ago, IamAQ said:

But I want to know who to use a hook, Is there a need to call hook function?

no - once you add them to /includes/hooks, then they will run automatically.

6 hours ago, IamAQ said:

I know we create hook file inside include/hooks directory. Can we name hook file whatever we want?

more or less, but it needs to end in .php

6 hours ago, IamAQ said:

Or we have to call that hook function in our templates code, where we want to make changes.?

there's no need to do anything to the template to make a hook run... now, if the hook is returning variables that you want to output, then you may need to edit the template - but not to make it run.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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