adamjedgar Posted June 3, 2019 Share Posted June 3, 2019 (edited) Hi guys, I want to use stock control as a means of restricting overselling hosting services on my servers (a kind of failsafe i guess) I note that we can hide or unhide stock control in WHMCS ( Setup>Products/Services>Edit Product>Stock Control Checkbox), however, i dont really want the stock control data to show up in the client area for each product/service as it currently does. What i would like to be able to do is put a limiter in place that only allows say 10 hosting packages to be purchased on a particular server...ie once 10 are sold, no more can be purchased on this machine. I realise that one can simply assign whmcs to automatically choose the next available server, however, i want something more finite...ie if there are no more servers available it simply doesnt allow any more sales of packages on said server. Clients would then need to choose another if one is available. How would i go about achieving that goal in WHMCS? 1. Is the best method to do this, setting the stock control to active(inputting a max number), then hiding the data on the client area using custom css? 2. If css, what css do i need to use for this? 3. I dont want to have to input custom css for every product service, is there a css method for achieving this - a. by group - b. globally Edited June 3, 2019 by adamjedgar 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 4, 2019 Share Posted June 4, 2019 I would start with this: <?php use WHMCS\Database\Capsule; add_hook('AfterModuleCreate', 1, function($vars) { $Sales = Capsule::select(Capsule::raw('SELECT t2.packageid, t1.qty - COUNT(t2.packageid) AS diff FROM tblproducts AS t1 LEFT JOIN tblhosting AS t2 ON t1.id = t2.packageid WHERE t1.qty > "0" AND t1.stockcontrol = "0" AND t2.domainstatus IN ("Active", "Suspended") GROUP BY t2.packageid')); foreach ($Sales as $v) { Capsule::select(Capsule::raw('UPDATE tblproducts SET hidden = "' . ($v->diff >= '0' ? '0' : '1') . '" WHERE id = "' . $v->packageid . '" LIMIT 1')); } }); add_hook('AfterModuleTerminate', 1, function($vars) { $Sales = Capsule::select(Capsule::raw('SELECT t2.packageid, t1.qty - COUNT(t2.packageid) AS diff FROM tblproducts AS t1 LEFT JOIN tblhosting AS t2 ON t1.id = t2.packageid WHERE t1.qty > "0" AND t1.stockcontrol = "0" AND t2.domainstatus IN ("Active", "Suspended") GROUP BY t2.packageid')); foreach ($Sales as $v) { Capsule::select(Capsule::raw('UPDATE tblproducts SET hidden = "' . ($v->diff >= '0' ? '0' : '1') . '" WHERE id = "' . $v->packageid . '" LIMIT 1')); } }); Every time you setup or terminate any of your special products (more on that later) the above hook performs a query that calculates the difference between your limits and total sales for each product. Let's suppose that we have the following scenario: Hosting Silver Limit: 10 Sales: 9 (Active + Suspended) Hosting Gold Limit: 5 Sales: 5 (Active + Suspended) A customer orders Hosting Silver. By running ModuleCreate the product becomes hidden (10/10 limit reached). Few minutes later you ModuleTerminate an expired Hosting Gold that becomes visibile (5/4 free slot). The only requirement is that all your special products must have Stock Control DISABLED and Quantity in Stock DEFINED. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 5, 2019 Share Posted June 5, 2019 On 03/06/2019 at 23:10, adamjedgar said: 2. If css, what css do i need to use for this? to hide the stock level amount from the Products page in the cart is Standard Cart... .qty {display: none;} ... though if you're using a custom cart template, the specific css may be different. 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.