Jump to content

option to set a client group as default


sahostking

Recommended Posts

12 minutes ago, sahostking said:

Any way yet to set client groups to profile on purchase of a certain package by default?

not from the settings - it would need a hook or addon.

there is an addon that would supposedly do it, Set Client Groups, but the developer has gone missing, support is non-existent and I don't think it's been updated for a while either... I wouldn't recommend buying it. naughty.gif

as a hook, when product x has been purchased, you're looking at updating the tblclients table (which stores which group the client belongs to) - either with a db update query or by using the updateclient API...

Link to comment
Share on other sites

<?php

/**
 * Replace somePrefix with something else to avoid function name collissions
 */

use WHMCS\Database\Capsule;

function somePrefix_AcceptOrder($vars)
{
    $groupID    = 1; // Replace with the ID of your Client Group
    $userID     = Capsule::table('tblorders')->where('id', $vars['orderid'])->first(['userid']);
    Capsule::table('tblclients')->where('id', $userID->userid)->update(['groupid' => $groupID]);
}

add_hook('AcceptOrder', 1, 'somePrefix_AcceptOrder');

It triggers when you Accept the order.

Edited by Kian
Link to comment
Share on other sites

use WHMCS\Database\Capsule;

function somePrefix_AcceptOrder($vars)
{
    $productID  = 12; // Replace with the ID of your Product/Service
    $groupID    = 1; // Replace with the ID of your Client Group
    $userID     = Capsule::table('tblorders')->leftJoin('tblhosting', 'tblorders.id', '=', 'tblhosting.orderid')->where([['tblorders.id', '=', $vars['orderid']], ['tblhosting.packageid', '=', $productID]])->first(['tblorders.userid']);

    if ($userID)
    {
        Capsule::table('tblclients')->where('id', $userID->userid)->update(['groupid' => $groupID]);
    }
}

add_hook('AcceptOrder', 1, 'somePrefix_AcceptOrder');

It should be okay now.

Link to comment
Share on other sites

4 minutes ago, sahostking said:

How would we set it for more than 1 product?

$productID  = [1,12]; // Replace with the ID of your Product/Service
$userID     = Capsule::table('tblorders')->leftJoin('tblhosting', 'tblorders.id', '=', 'tblhosting.orderid')->where('tblorders.id',$vars['orderid'])->whereIn('tblhosting.packageid', $productID)->first(['tblorders.userid']);

 

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