Jump to content
Nick A

Limit Product to 1 Per Account

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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 by Nick A

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
<?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");

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated