Jump to content
  • 0

Client Area panel only If Client has active Service


Synister

Question

Im wanting to add a custom Client Area Panel but only want it to show if client has a active service.

If not active service or service is Canceled, Terminated, Pending, ETC I dont want the panel to show. is this possible?

 

<?php

use WHMCS\View\Menu\Item;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
    $ServiceMessage = <<<EOT
<p>

PANNEL MESSAGE HERE

</p>
EOT;

    $homePagePanels->addChild('servmsg', array(
        'label' => 'PANEL TITLE HERE',
        'icon' => 'fa-exclamation-triangle',
        'order' => 10,
        'extras' => array(
            'color' => 'pomegranate',
            'btn-link' => 'http://button.link.here', // button link - CHANGE THIS
            'btn-text' => 'BUTTON TITLE HERE', 
            'btn-icon' => 'fa-arrow-right',
        ),
        'bodyHtml' => $ServiceMessage,
        'footerHtml' => 'Thank You for Choosing Us.', // bottom message
    ));
});

 

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0
11 hours ago, Synister said:

If not active service or service is Canceled, Terminated, Pending, ETC I dont want the panel to show. is this possible?

it wouldn't be a million miles away from the hook posted in the thread below - the important part being that all your output is within the IF statement.

Link to comment
Share on other sites

  • 0
On 2/28/2021 at 9:46 AM, brian! said:

it wouldn't be a million miles away from the hook posted in the thread below - the important part being that all your output is within the IF statement.

Ok that did not work.

Even adding the code on the Post you shared did not work. It shows if client has active product, but if client does not have active product they get a OOPS page.

Below is what I used just to see if it would work. It is from the link you shared.

 

<?php

use WHMCS\View\Menu\Item;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
    $client = Menu::context('client');
	$activeorders = $client->orders->where('status','Active')->count();
	if ($client && $activeorders > 0) {
        
        $fraudPanel = $homePagePanels->addChild('account status', array(
            'label' => 'Account Status',
            'icon' => 'fas fa-user-shield',
            'extras' => array(
                'color' => 'blue',
            ),
            'bodyHtml' => "<p>Account Status: <strong>Premium Account</strong></p>",
        ));
    }

    // Showing to First Panel
    $fraudPanel->moveToFront();
});

 

Link to comment
Share on other sites

  • 0

The oops happens because $fraudPanel does not exist at $fraudPanel->moveToFront(); when there are no active orders and thus produces a fatal error of "tried to use a function on a non-member object" or something like that.   You either want to place that bit within the same scope, within the if clause you init it in), or another if (with isset, function exists, is_a, or other etc checks) to ensure $fraudPanel exists.  

Enabling displaying of php errors in general settings -> other -> display errors should help in the future to determine what the error is. 

Edited by steven99
Link to comment
Share on other sites

  • 0
59 minutes ago, steven99 said:

The oops happens because $fraudPanel does not exist at $fraudPanel->moveToFront(); when there are no active orders and thus produces a fatal error of "tried to use a function on a non-member object" or something like that.   You either want to place that bit within the same scope, within the if clause you init it in), or another if (with isset, function exists, is_a, or other etc checks) to ensure $fraudPanel exists.  

Enabling displaying of php errors in general settings -> other -> display errors should help in the future to determine what the error is. 

I removed the move to front, still no luck. Now it wont show up on either Active or No Active Product clients.

I turned on display error and nothing showed.

 

<?php

use WHMCS\View\Menu\Item;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
    $client = Menu::context('client');
	$activeorders = $client->orders->where('status','Active')->count();
	if ($client && $activeorders > 0) {
        
        $fraudPanel = $homePagePanels->addChild('account status', array(
            'label' => 'Account Status',
            'icon' => 'fas fa-user-shield',
            'extras' => array(
                'color' => 'blue',
            ),
            'bodyHtml' => "<p>Account Status: <strong>Premium Account</strong></p>",
        ));
});

 

Edited by Synister
Link to comment
Share on other sites

  • 0

Today while testing this a little further I noticed this.

If Client has never ordered any products the Panel does not show.
If Client has and Products (Active/Canceled/ Terminated) The panel shows.
How can I get it to only show if a client has a product that is active?

Link to comment
Share on other sites

  • -1

The above code has the missing } for if the client and active orders.  See below code that I have tested and works in 8 . Again it was just moving the move to front up in to if scope.

<?php

use WHMCS\View\Menu\Item;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
    $client = Menu::context('client');
        $activeorders = $client->orders->where('status','Active')->count();
        if ($client && $activeorders > 0) {

        $fraudPanel = $homePagePanels->addChild('account status', array(
            'label' => 'Account Status',
            'icon' => 'fas fa-user-shield',
            'extras' => array(
                'color' => 'blue',
            ),
            'bodyHtml' => "<p>Account Status: <strong>Premium Account</strong></p>",
        ));

  // Showing to First Panel
    $fraudPanel->moveToFront();

    }

});

image.png.e734465fd31dfcf4f56de49c5ece0186.png

Edited by steven99
added screenshot.
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
Answer this question...

×   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