sahostking Posted July 12, 2018 Share Posted July 12, 2018 Any way yet to set client groups to profile on purchase of a certain package by default? Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 12, 2018 Share Posted July 12, 2018 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. 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... 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted July 12, 2018 Share Posted July 12, 2018 (edited) <?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 July 12, 2018 by Kian 1 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 13, 2018 Share Posted July 13, 2018 17 hours ago, Kian said: It triggers when you Accept the order. it's also worth noting that, as written, it runs after every order and changes the client group - regardless of the product(s) ordered. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted July 13, 2018 Share Posted July 13, 2018 1 hour ago, brian! said: it's also worth noting that, as written, it runs after every order and changes the client group - regardless of the product(s) ordered. Ah! 😖 I'm going to update it. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted July 13, 2018 Share Posted July 13, 2018 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. 0 Quote Link to comment Share on other sites More sharing options...
sahostking Posted July 13, 2018 Author Share Posted July 13, 2018 How would we set it for more than 1 product? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 13, 2018 Share Posted July 13, 2018 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']); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.