mindaugas Posted September 9, 2011 Share Posted September 9, 2011 Is there a way to limit one product per customer/client? Meaning, a customer cannot order a new product unless they create a new account. 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted September 9, 2011 Share Posted September 9, 2011 Assuming they'll have a unique email address for each account - yes Just remove the "existing customer" section from the order/checkout template 0 Quote Link to comment Share on other sites More sharing options...
Brett Posted September 9, 2011 Share Posted September 9, 2011 Assuming they'll have a unique email address for each account - yesJust remove the "existing customer" section from the order/checkout template What if they are logged in? I don't think there is anything that can be done about that... 0 Quote Link to comment Share on other sites More sharing options...
sdemidko Posted September 18, 2011 Share Posted September 18, 2011 What if they are logged in? I don't think there is anything that can be done about that... usually implementing a very special features in templates I use {php}{/php}, not very intellegent but still working so you will need to do couple queries to DB to define if there is already a product for certain client or you can use internal API, which would be the better solution I guess - http://docs.whmcs.com/API:Get_Clients_Products remember to define variable via PHP directly in smarty template you'll need this: $this->_tpl_vars['your_variable'] = 'your_value'; 0 Quote Link to comment Share on other sites More sharing options...
Chrystopher Posted May 18, 2012 Share Posted May 18, 2012 Hi, I was just wondering if anyone knew how to limit one product per customer? Is this possible? I don't really want to be making template changes as we only want to limit one of our products and not all of them. Thank you in advance. 0 Quote Link to comment Share on other sites More sharing options...
k1ng440 Posted May 20, 2012 Share Posted May 20, 2012 you can do this with ShoppingCartValidateCheckout hook. <?php function limitOrders($vars) { if(mysql_num_rows(mysql_query("SELECT id FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'")) > 0) { global $errormessage; $errormessage = "<li>limit one product per customer Reply to Thread</li>"; } } add_hook("ShoppingCartValidateCheckout", 1, "limitOrders"); ?> 0 Quote Link to comment Share on other sites More sharing options...
Manchester Web Hosting Posted May 29, 2012 Share Posted May 29, 2012 you can do this with ShoppingCartValidateCheckout hook. <?php function limitOrders($vars) { if(mysql_num_rows(mysql_query("SELECT id FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'")) > 0) { global $errormessage; $errormessage = "<li>limit one product per customer Reply to Thread</li>"; } } add_hook("ShoppingCartValidateCheckout", 1, "limitOrders"); ?> So all you would do is replace 0 in ''{$_SESSION['uid']}'")) > 0)' with uid of your product?? 0 Quote Link to comment Share on other sites More sharing options...
SilverNodashi Posted May 31, 2012 Share Posted May 31, 2012 how would one limit ProductA to "1 per client", but ProductB & ProductC not? 0 Quote Link to comment Share on other sites More sharing options...
disgruntled Posted June 1, 2012 Share Posted June 1, 2012 (edited) you can do this with ShoppingCartValidateCheckout hook. <?php function limitOrders($vars) { if(mysql_num_rows(mysql_query("SELECT id FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'")) > 0 AND 'xxx' = 'yyy') { global $errormessage; $errormessage = "<li>limit one product per customer Reply to Thread</li>"; } } add_hook("ShoppingCartValidateCheckout", 1, "limitOrders"); ?> Check the database in tblhosting for the correct field to check against, replace xxx Check the product for the correct product id, replace yyy The sql is saying, select clients userid from tblhosting where product is more than zero, if the product exists for you will get their id, in this case they wont be able to continue the order. As for seperate client emails, they can make as many as they want to make on a single domain and each will be different, if you wish you could also drop in a second sql check or just join one to this to check if the email domain is used, the problem is you would need a whitelist of domains for mail services like hotmail etc as they are multi user domains where a private domain for the most part is not. Edited June 1, 2012 by disgruntled 0 Quote Link to comment Share on other sites More sharing options...
_Dudu_1533 Posted October 20, 2012 Share Posted October 20, 2012 (edited) I've developed a Hook to do this! It works perfectly! function limitOrders($vars) { $array = array(7, ; // List of free produtcs (ids) for($i = 0; $i < count($_SESSION['cart']['products']); $i++) { $sql = mysql_query("SELECT *, (SELECT `name` FROM tblproducts WHERE id = packageid) AS product FROM tblhosting WHERE userid = ".$_SESSION['uid']." AND packageid = ".$_SESSION['cart']['products'][$i]['pid']) or die(mysql_error()); if(mysql_num_rows($sql) > 0) { $c = mysql_fetch_array($sql); if(in_array($c['packageid'], $array)) { global $errormessage; $errormessage = "<li>Você já possui uma licença FREE do produto <b>".$c['product']."</b>!</li>"; //Portuguese message //$errormessage = "<li>You already have a FREE license of <b>".$c['product']."</b>!</li>"; //English message } } } } add_hook("ShoppingCartValidateCheckout", 1, "limitOrders"); Just put the ID of free products in the $array variable... Edited October 20, 2012 by _Dudu_1533 0 Quote Link to comment Share on other sites More sharing options...
matthall28 Posted March 29, 2013 Share Posted March 29, 2013 I've developed a Hook to do this!It works perfectly! function limitOrders($vars) { $array = array(7, ; // List of free produtcs (ids) for($i = 0; $i < count($_SESSION['cart']['products']); $i++) { $sql = mysql_query("SELECT *, (SELECT `name` FROM tblproducts WHERE id = packageid) AS product FROM tblhosting WHERE userid = ".$_SESSION['uid']." AND packageid = ".$_SESSION['cart']['products'][$i]['pid']) or die(mysql_error()); if(mysql_num_rows($sql) > 0) { $c = mysql_fetch_array($sql); if(in_array($c['packageid'], $array)) { global $errormessage; $errormessage = "<li>Você já possui uma licença FREE do produto <b>".$c['product']."</b>!</li>"; //Portuguese message //$errormessage = "<li>You already have a FREE license of <b>".$c['product']."</b>!</li>"; //English message } } } } add_hook("ShoppingCartValidateCheckout", 1, "limitOrders"); Just put the ID of free products in the $array variable... This method doesn't seem to work anymore, you get a MySQL error when signing up with a new account. Any suggestions? 0 Quote Link to comment Share on other sites More sharing options...
apexio Posted May 7, 2013 Share Posted May 7, 2013 Check the database in tblhosting for the correct field to check against, replace xxxCheck the product for the correct product id, replace yyy The sql is saying, select clients userid from tblhosting where product is more than zero, if the product exists for you will get their id, in this case they wont be able to continue the order. As for seperate client emails, they can make as many as they want to make on a single domain and each will be different, if you wish you could also drop in a second sql check or just join one to this to check if the email domain is used, the problem is you would need a whitelist of domains for mail services like hotmail etc as they are multi user domains where a private domain for the most part is not. That didn't quite work for me in the latest WHMCS (5.24). This does though: <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); function limitOrders($vars) { if(mysql_num_rows(mysql_query("SELECT packageid FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'")) > 0) { if($packageid = '2') { global $errormessage; $errormessage = "<li>Sorry, you already have a Free VPS account and there's a limit of one per user.</li>"; } } } add_hook("ShoppingCartValidateCheckout", 1, "limitOrders"); ?> Change the '2' to the product id of the product you want to limit orders of. 0 Quote Link to comment Share on other sites More sharing options...
paperweight Posted July 4, 2013 Share Posted July 4, 2013 Awesome, I was looking for this same thing. I need to allow only 1 product across my entire site regardless of free or paid. Even for paid products I want to limit user to only 1 paid product. I have the following quick questions: 1) This does not affect upgrades, right? If a user upgrades from a Low to Medium, this hook will not conflict and say they can not upgrade, right? 2) This goes in /includes/hooks, right? Does it matter what to name the file? cheers~ 0 Quote Link to comment Share on other sites More sharing options...
paperweight Posted July 4, 2013 Share Posted July 4, 2013 Ok I tested it and it appears to work very well. I placed it in /includes/hooks and named it "limit1product.php". 0 Quote Link to comment Share on other sites More sharing options...
towens Posted July 10, 2013 Share Posted July 10, 2013 This works great for existing customers with a product already in the system, but is there a way to modify the hook to make sure a shopping cart can't have more than 1 product? We have a free hosting/domain package and want to limit it to one per user but currently a user can get to the end of the shopping cart and then back up and add another, and another... 0 Quote Link to comment Share on other sites More sharing options...
paperweight Posted July 10, 2013 Share Posted July 10, 2013 This works great for existing customers with a product already in the system, but is there a way to modify the hook to make sure a shopping cart can't have more than 1 product? We have a free hosting/domain package and want to limit it to one per user but currently a user can get to the end of the shopping cart and then back up and add another, and another... Hmmmm... you are very correct! I just tested that and you are right that if a user continues shopping, they can purchase multiple products/services. Damn... I had not tested that aspect of it. Ok, so then there needs to be part of the hook that qualifies only one product on checkout maybe and then tells user to delete all but one product? Or is there a simpler way? I am not a great programmer so I will listen to your ideas... 0 Quote Link to comment Share on other sites More sharing options...
mburtis Posted July 19, 2013 Share Posted July 19, 2013 I wanted to come back and say that we found a way to do this with items currently in the order by using the WHMCS Product Limiter Addon (which is free): http://www.jetserver.net/whmcs-product-limiter. A couple of caveats: * Product Limiter only removes the product that violates the limitation that you've set up. In our case, we had a free domain linked to that hosting product, so I had to add some code to the plugin to remove not only the last product but the last domain, too: In hooks.php, find the line that reads: unset($_SESSION['cart']['products'][$cart_items[count($cart_items) - 1]]); and below it add the following: unset($_SESSION['cart']['domains'][$cart_items[count($cart_items) - 1]]); * If a customer has repeatedly added the same (limited) product, they have to cycle through the checkout a couple of times until the amounts in their cart fall below the limit. 0 Quote Link to comment Share on other sites More sharing options...
paperweight Posted July 20, 2013 Share Posted July 20, 2013 I wanted to come back and say that we found a way to do this with items currently in the order by using the WHMCS Product Limiter Addon (which is free): http://www.jetserver.net/whmcs-product-limiter. Thank you so much for the tip! I just visited the site and registered an account and added the plugin to my account, but it appears no where -- seems like no place to download it once I am logged in. when I try to "buy" the free addon again, it tells me I can only purchase 1 at a time. So it seems to work, though it doesn;t appear where I can download the plugin from. Very weird.... 0 Quote Link to comment Share on other sites More sharing options...
paperweight Posted July 21, 2013 Share Posted July 21, 2013 Sorry, I went back to that site, logged in, and did another purchase of the addon. I now have it successfully and will test it in the next 2 days and report back any problems. 0 Quote Link to comment Share on other sites More sharing options...
mburtis Posted July 22, 2013 Share Posted July 22, 2013 Yeah -- I had the same issue with downloading the plugin. The site seems to use WHMCS for the interface which is. . . ironic. ;-) 0 Quote Link to comment Share on other sites More sharing options...
Swehoster Posted November 26, 2013 Share Posted November 26, 2013 Hi. This worked great. Now on the latest version 5.2.13 I think it is not any more. I just can't say why but the check isn't done. Anyone that has experienced the same issue? Best regards 0 Quote Link to comment Share on other sites More sharing options...
paperweight Posted November 26, 2013 Share Posted November 26, 2013 Right, thanks for the update. I just tested it and you are correct: it seems to now be broken 0 Quote Link to comment Share on other sites More sharing options...
Swehoster Posted November 26, 2013 Share Posted November 26, 2013 It looks like it is working on clients but not new visitors or unregistered clients/visitors. 0 Quote Link to comment Share on other sites More sharing options...
elialum Posted December 17, 2013 Share Posted December 17, 2013 Hi, We've released a new version of WHMCS Product limiter, it's now working with version 5.2.14 Release notes - http://www.jetserver.net/doc/wpl/rnotes Eli. 0 Quote Link to comment Share on other sites More sharing options...
paperweight Posted December 17, 2013 Share Posted December 17, 2013 Great thank you~ thanks for all your hard work~ I just tried to download with the same username I used last time and I get this error: "You can't order "WHMCS Limit Products/Services Purchase" more then one time" Is it possible to re-download this with my same username or should I use a different registration? 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.