Jump to content

Error: Call to a member function getChild()


krlos777

Recommended Posts

Hello, I am trying to modify the client sidebar using the following code:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
    $primarySidebar->getChild("My Account")
        ->getChild("Billing Information")
        ->setLabel("Custom Text Here");
});

But when I reload client area I get this error:

Error: Call to a member function getChild() on null in .....

 

Link to comment
Share on other sites

the problem with that hook is that you're not first checking whether what you want to modify exists on the current page before trying to modify it - so I imagine it would work fine on a page where that sidebar child exists, but fail on every other page.

but if all you're wanting to do is change a label on a default sidebar child, then you don't need to use a hook for that, you can use Language Overrides instead.

$_LANG['sidebars']['viewAccount']['billingInformation'] = "Billing Information";

just follow the instructions in the docs to create an overrides folder in the /lang file and add your changes to that string for each language within their own file in that new folder.

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