Nick A Posted September 10, 2019 Share Posted September 10, 2019 I've been searching for a solution for a while, but most of the threads about this topic seem outdated. What would be the best way to prevent customers from ordering more than one of product XYZ? If they're a new customer/not logged in, I'd like to prevent them from adding more than one XYZ to the cart. If they're an existing customer, I'd like to prevent them from ordering another XYZ if one is already on their account. Does anyone have a similar v7 compatible hook for this already? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 11, 2019 Share Posted September 11, 2019 13 hours ago, Nick A said: I've been searching for a solution for a while, but most of the threads about this topic seem outdated. lots of old solutions still work on WHMCS. 😉 13 hours ago, Nick A said: What would be the best way to prevent customers from ordering more than one of product XYZ? If they're a new customer/not logged in, I'd like to prevent them from adding more than one XYZ to the cart. If they're an existing customer, I'd like to prevent them from ordering another XYZ if one is already on their account. I think the old free Product Limiter addon on GitHub still works - as long as you're not using PHP7 or later (I believe it's the old SQL code that breaks it in PHP7 - but still works with PHP5.6). there is a commercial solution in Marketplace if you want to pay $25 for this. 13 hours ago, Nick A said: Does anyone have a similar v7 compatible hook for this already? I still think that GitHub addon can be fixed for PHP7 - it should mainly be a case of updating the SQL queries used within it. 0 Quote Link to comment Share on other sites More sharing options...
Nick A Posted September 11, 2019 Author Share Posted September 11, 2019 (edited) Tried the marketplace module. It won't let an existing customer checkout with a second product XYZ if they already have one on their account, but it doesn't prevent someone from ordering 2 x product XYZ initially. I'm assuming a hook could handle the other half the equation: "prevent adding more than 1 XYZ per cart" ? Edit: never mind - we figured out a hook to silently block adding multiple of XYZ to the cart. Works well in combination with the paid add-on. Edited September 11, 2019 by Nick A 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 12, 2019 Share Posted September 12, 2019 14 hours ago, Nick A said: Edit: never mind - we figured out a hook to silently block adding multiple of XYZ to the cart. Works well in combination with the paid add-on. which I hope you are going to share in case others are in the same boat. 0 Quote Link to comment Share on other sites More sharing options...
Nick A Posted September 12, 2019 Author Share Posted September 12, 2019 <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); function nodupepids($vars) { $nodupepids = array('<product ID>'); foreach ($_SESSION['cart']['products'] as $key => $value) { if (in_array($value[pid], $pidsfound)) { header('Location: cart.php?a=remove&r=p&i=' . $key); } if (in_array($value[pid], $nodupepids)) { $pidsfound[] = $value[pid]; } } } add_hook("PreCalculateCartTotals", 1, "nodupepids"); Â 1 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.