Jump to content

Remove Sidebar from product detail page


Dhush

Recommended Posts

Well, for certain groups of it, how I do it.

if it's just one product group, you can do this...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   $service = Menu::context('service');  
   $gid = $service->product->productGroupId;

   if ($gid == '10') {

       if (!is_null($primarySidebar->getChild('Service Details Actions'))) {
                    $primarySidebar->removeChild('Service Details Actions');
       }
       if (!is_null($primarySidebar->getChild('Service Details Overview'))) {
                    $primarySidebar->removeChild('Service Details Overview');
       }
   }
});

if it's more than one product group (or even more than one product - or a mix of products and groups), then you simply add an OR to the if statement...

 

    if ($gid == '1' OR $gid == '11') {

Link to comment
Share on other sites

do pwreset and login have any sidebars by default? or even any common sidebars between them all ??

 

anyway, for those 4 examples, they all use different pages, so you can use...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   $filename = APP::getCurrentFileName();
   if ($filename=='register' || $filename=='pwreset') {

       if (!is_null($primarySidebar->getChild('Already Registered'))) {
                    $primarySidebar->removeChild('Already Registered');
       }
   }
}); 

Link to comment
Share on other sites

Ooo thanks for the response! i didn't test it out yet but i reckon you type the truth!

 

actually, i was specifically interested in removing the sidebars on the domain register page, but when i copy / paste the code from my header file i forgot to edit it.

 

i reckon, with the foundation you provided, i should be able to work with it and remove the "categories" sidebar that appears on those domain register pages.

Link to comment
Share on other sites

Made a rookie mistake, I meant to paste in code for:

 

\whmcs\templates\orderforms\standard_cart\domainregister.tpl

\whmcs\templates\orderforms\standard_cart\domaintransfer.tpl

 

specifically, the categories sidebar. i tried a few things, but i didn't get any luck. am i missing a charecter something?

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   $filename = APP::getCurrentFileName();
   if ($filename=='viewcart') {

       if (!is_null($primarySidebar->getChild('Actions'))) {
                    $primarySidebar->removeChild('Actions');
       }
   }
});

 

and

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   $filename = APP::getCurrentFileName();
   if ($filename=='domainregister' || $filename=='domaintransfer' || $filename=='viewcart') {

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

Link to comment
Share on other sites

  • 4 months later...
it is possible to move the sidebars to the navbar - it's relatively simple to do, but it can/will get complicated when you need to fine tune it. :cry:

 

as you only want to do this on one page, here's what you need to do.

 

step 1 - delete the above hook file... for this method to work, we do not want to remove the sidebar via the action hook method.

step 2 - in /templates/six (or your custom template based on six)/header.tpl change the following at the end of the file...

 

<section id="main-body" class="container">

   <div class="row">
       {if !$inShoppingCart && ($primarySidebar->hasChildren() || $secondarySidebar->hasChildren())}
           {if $primarySidebar->hasChildren()}
               <div class="col-md-9 pull-md-right">
                   {include file="$template/includes/pageheader.tpl" title=$displayTitle desc=$tagline showbreadcrumb=true}
               </div>
           {/if}
           <div class="col-md-3 pull-md-left sidebar">
               {include file="$template/includes/sidebar.tpl" sidebar=$primarySidebar}
           </div>
       {/if}
       <!-- Container for main page display content -->
       <div class="{if !$inShoppingCart && ($primarySidebar->hasChildren() || $secondarySidebar->hasChildren())}col-md-9 pull-md-right{else}col-xs-12{/if} main-content">
           {if !$primarySidebar->hasChildren() && !$showingLoginPage && !$inShoppingCart && $templatefile != 'homepage'}
               {include file="$template/includes/pageheader.tpl" title=$displayTitle desc=$tagline showbreadcrumb=true}
           {/if}

to...

 

<section id="main-body" class="container">

   <div class="row">
       {if !$inShoppingCart && ($primarySidebar->hasChildren() || $secondarySidebar->hasChildren()) && $templatefile neq 'clientareaproductdetails'}
           {if $primarySidebar->hasChildren()}
               <div class="col-md-9 pull-md-right">
                   {include file="$template/includes/pageheader.tpl" title=$displayTitle desc=$tagline showbreadcrumb=true}
               </div>
           {/if}
           <div class="col-md-3 pull-md-left sidebar">
               {include file="$template/includes/sidebar.tpl" sidebar=$primarySidebar}
           </div>
       {/if}
       <!-- Container for main page display content -->
       <div class="{if !$inShoppingCart && ($primarySidebar->hasChildren() || $secondarySidebar->hasChildren()) && $templatefile neq 'clientareaproductdetails'}col-md-9 pull-md-right{else}col-xs-12{/if} main-content">
           {if !$primarySidebar->hasChildren() && !$showingLoginPage && !$inShoppingCart && $templatefile != 'homepage' || $templatefile eq 'clientareaproductdetails'}
               {include file="$template/includes/pageheader.tpl" title=$displayTitle desc=$tagline showbreadcrumb=true}
           {/if}

this removes the entire sidebar from only the "Product Details" page in the client area, and adjusts the output width.

 

step 3 - now we can move the sidebar to the navbar and to do this, we make another change to header.tpl by replacing...

 

                <ul class="nav navbar-nav">

                   {include file="$template/includes/navbar.tpl" navbar=$primaryNavbar}

               </ul>

with...

 

                <ul class="nav navbar-nav">
                   {if $templatefile eq 'clientareaproductdetails'}{include file="$template/includes/navbar.tpl" navbar=$primarySidebar}{/if}
                   {include file="$template/includes/navbar.tpl" navbar=$primaryNavbar}
               </ul>

if you do that, then the sidebars will now appear (and work!) in the navbar...

IGjmpaR.png

 

as shown in the above example, i've put the 'sidebar' at the beginning of the navbar - using this method, you really only have four places where you can add it - at the beginning/end of either the primary (1/2) or secondary navbars (3/4)...

 

xNzXQv9.png

what you cannot do, before you even ask me about doing it(!), is place these sidebar(s) anywhere within an existing navbar, e.g within the "Services" dropdown... it's probably not impossible, but would either require some clever array manipulation in PHP or complex Smarty template edits - neither of which I fancy wasting any of my time on! :idea:

 

if you needed to put these sidebar links in a specific spot, then it would be easier to add additional links to the navbar using an action hook - but you would need to recreate the links in the hook, rather than embedding a pre-existing sidebar into the navbar as we are doing here.

 

so the above code places the sidebar in the (1) location in the navbar - if you wanted it at the end of the navbar (2), you would use...

 

                <ul class="nav navbar-nav">
                   {include file="$template/includes/navbar.tpl" navbar=$primaryNavbar}
                   {if $templatefile eq  'clientareaproductdetails'}{include file="$template/includes/navbar.tpl"  navbar=$primarySidebar}{/if}
               </ul>

and you'll somethink see this...

RmrpEiU.png

 

if you wanted it around the secondary navbar (3 or 4), then you would edit the code below instead in a similar way...

 

                <ul class="nav navbar-nav navbar-right">
                   {include file="$template/includes/navbar.tpl" navbar=$secondaryNavbar}
               </ul>

also, for those reading this thread and interested in using the idea in other pages, you can do so - either adding primary and/or secondary sidebars to the navbar... the product details page only uses a primary sidebar, but other pages have both... some primary sidebars aren't suitable for this method, e.g filter sidebars - I can see why they don't work, and if I ever write a proper tutorial about this, i'll look into it finding a possible fix (but as I say some of them will never be suitable for navbar).... I think all the secondary sidebars that i've tested this with have behaved correctly. :idea:

 

I should also mention that, as far as WHMCS is concerned, these are still sidebars and can therefore still be manipulated via action hooks... e.g on that first image where you have "Overview" / "Actions" / "Home", it's a little weird to have "Home" third, so if you wanted to move it to first, what you could do is use a hook to remove it from the navbar, and then another hook (in the same file) to add a "Home" link to the top of the primary sidebar... which would effectively move the "Home" link from 3rd to 1st.

 

that's where it can get a little complicated - moving the child menuitems is easy, but for others planning on using this method more widely, you should really plan which menus you want and where and then write the hooks to do that... and also check that there is enough space in the navbar to show both the default navbars and these sidebars together (on some there isn't).

 

finally, and slightly off-topic, but someone once asked me about showing the Product Categories (Product Groups) from the cart in the navbar instead - this method can be used to do that...

 

                <ul class="nav navbar-nav">
                   {if $filename eq 'cart'}{include file="$template/includes/navbar.tpl" navbar=$secondarySidebar}{/if}                
                   {include file="$template/includes/navbar.tpl" navbar=$primaryNavbar}
               </ul>

and you'll see...

Lm7VHk3.png

 

with this method, "Categories" and "Actions" will work... "Change Currency" won't - but you don't need it to anyway as i've previously described how to move the currency to the notification box.

 

http://forum.whmcs.com/showthread.php?115658-currency-selector-on-header-tpl&p=467638#post467638

 

what you would do is similar to the above method - you'd hide the sidebar in the template and then use a hook to remove the "Choose Currency" sidebar - that would remove it from the navbar too.

 

as I said previously, i'll probably write this up into a tutorial at some point and explore the issues more thoroughly. :)

 

- - - Updated - - -

 

 

that's the usual way to add links! :idea:

 

 

 

 

 

Hello Brian,

 

Thank you very much for this reply. This helped me to remove the sidebar from my product details pages of the client panel. Can you please point me on how to remove the sidebar from my checkout and payment areas as well. How can I improve this code to include the part to remove the sidebar from the checkout pages/templates as well.

checkout2.jpg

Link to comment
Share on other sites

  • 5 weeks later...
I'm also interested in removing from all pages those two menus (Categories and Actions).

you can do that by using the action hook code below...

 

<?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');
   }    
});

Link to comment
Share on other sites

I had in my mind that the main body will take sidebar's place by going full width, however it is not and that leads to an empty space.

I had in my mind you weren't removing the currency sidebar, so assumed that there would still be something there and so empty sidebar space would not be an issue! :)

 

what you're seeing is absolutely correct - standard_cart is designed (badly) to always assume there will be a sidebar there and leaves a space for it... if you want to get rid of that space, then you'll need to edit the cart template(s)...

 

https://forum.whmcs.com/showthread.php?106435-how-to-remove-the-left-column-in-some-page-whmcs-6-1&p=437590#post437590

 

that's a thread from 2 years ago and still WHMCS haven't fixed this... it would be very easy to do so, but they don't give it a high priority. :roll:

 

btw - if you're going to do this, then you don't need the previous hook as you won't be calling the sidebar template in the cart.

Link to comment
Share on other sites

  • 2 years later...

hi,

after placing the file in /includes/hooks/somefile.php , Clients redirecting back to login page when they want to register account, no error showing

, but removing file all working fine.

code:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   if (!is_null($primarySidebar->getChild('Service Details Overview'))) {
            $primarySidebar->removeChild('Service Details Overview');
   }
   if (!is_null($primarySidebar->getChild('Service Details Actions'))) {
            $primarySidebar->removeChild('Service Details Actions');
   }    

});

 

 

 

Link to comment
Share on other sites

On 02/04/2020 at 20:34, Ghani said:

after placing the file in /includes/hooks/somefile.php , Clients redirecting back to login page when they want to register account, no error showing

the hook you pasted shouldn't cause that error you're seeing - it's just removing sidebar(s) and that wouldn't have any impact on redirecting registering.

Link to comment
Share on other sites

yes it is working to remove the sidebar, but after placing it as hook, when clients want to register it going to login page and not register. not only this hook script  but placing any hooks script in it not working on clients registration .

with already exist two default script hooks working fine

example.php and index.php

 

Link to comment
Share on other sites

16 hours ago, Ghani said:

with already exist two default script hooks working fine

neither of them are working hooks - so they're doing nothing.

16 hours ago, Ghani said:

yes it is working to remove the sidebar, but after placing it as hook, when clients want to register it going to login page and not register. not only this hook script  but placing any hooks script in it not working on clients registration .

so if you remove the above sidebar hook, then clients can register without issue ? and you're hook file ends in .php and has a unique filename ??

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