Jump to content

How to check user if already have an active order before?


JuniYadi

Recommended Posts

Hi,

i'm just implementation fraud protection, and check on order setup for :

Tick this box to skip the fraud check for existing clients who already have an active order

i want to make widget in client area showing if user already have an active order, then it's show: you can order without fraud check.

any suggest query sql or how to do this?

 

Thanks

Selection-20200328-001.png

Link to comment
Share on other sites

8 hours ago, JuniYadi said:

i want to make widget in client area showing if user already have an active order, then it's show: you can order without fraud check.

if we keep it simple and make it a bootstrap alert for now, then the hook code would be a variation of the one I posted in the thread below...

8 hours ago, JuniYadi said:

any suggest query sql or how to do this?

you wouldn't particularly need a SQL query for this...

<?php

add_hook('ClientAreaHomepage', 1, function($vars) {
	$client = Menu::context('client');
	$activeorders = $client->orders->where('status','Active')->count();
	if ($client && $activeorders > 0) {
		return '<div class="text-center"><div class="alert alert-success" role="alert">You can order without fraud check - click <a href="cart.php">here</a>.</div></div><br />';
	}
});

so if the user has active orders, then an alert is shown on the homepage...

rZVmV8X.png

if the user has no active orders, then the message alert isn't shown.

snStoYB.png

... and if you still want to make it into a homepage panel (widget), then the first three lines inside the hook code would be the same, you would just need to follow the panel examples in the docs...

UeRDo5F.png

Link to comment
Share on other sites

Thank @brian!

Solved now, if someone need widget. and here the hooks.

<?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

  • 3 years later...

When I use the following code, it throws an error anytime a user is not logged in. Any ideas why?

 

add_hook('ClientAreaSidebars', 1, function()
{
	$client = Menu::context('client');
	$activeorders = $client->orders->where('status','Active')->count();
	if ($client && $activeorders > 0) {
		GLOBAL $smarty;
		$templatefile = $smarty->getVariable('templatefile');
		$allowedpages = ['clientareahome','homepage','knowledgebase'];
		if (in_array($templatefile, $allowedpages)) {
			$client = Menu::context('client');
			$secondarySidebar = Menu::secondarySidebar();
			$title = 'Write Us A Review';
			$bodyHtml = '<!-- CUSTOM HTML HERE -->';
			$secondarySidebar->addChild('Review')
				->setLabel($title)
				->setBodyHtml($bodyHtml)
				->setIcon('fa-star')
				->setOrder(100);
		}
	}
});

 

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