Jump to content

Limit Product to 1 Per Account


Nick A

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?

Link to comment
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.

Link to comment
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
Link to comment
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");

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

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