Jump to content

Adding child to Account menu


snake

Recommended Posts

I am trying to add a couple of custom menu items.

I have managed to add a child to the primary menu but I cannot get the secondary menu addition to work.

please note that I am not a php developer, I am just doing this from  reading the docs.

Here is what I have, can someone fix my code... thanks.

<?php

use WHMCS\View\Menu\Item as MenuItem;

/** this one works **/

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
    $primaryNavbar->addChild('Main Website')
        ->setUri('https://foodbooking.uk/')
        ->setOrder(2);
        
    
});

/** this one doesn't work , in fact  this code stops the one above from working too**/
add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar)
{
    if (!is_null($secondaryNavbar->getChild('Account'))) {
        $secondaryNavbar->getChild('Account')
            ->addChild('Restaurant Login', array(
                'label' => 'Restaurant Login'),
                'uri' => 'https://restaurantlogin.com',
                'order' => '100',
            ));
    }
});

Link to comment
Share on other sites

3 hours ago, snake said:

please note that I am not a php developer, I am just doing this from  reading the docs.

mistake number #1 lol 😛

3 hours ago, snake said:

Here is what I have, can someone fix my code... thanks.

you've left a closing bracket in the Restaurant Login label line...

'label' => 'Restaurant Login',

technically, you don't even need that entire line - if you remove it, the hook will still work and will just use the child's name - which is "Restaurant Login" anyway.

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