Jump to content

How to stop adding product if the product exist in cart


Recommended Posts

2 hours ago, REDOUANE said:

i want some help, if product exist in cart i don t want to add it to cart, is there a way to stop adding product if it exist in cart?

not from settings - so the solution would have to be coded.

there used to be a free addon years ago called Product Limiter, and if you are still using an older version of WHMCS, and not using PHP7 or later (so it wouldn't work in WHMCS v8), then I suspect it would still work.

@Kian posted a free hook, OneOffProductsDomainRequireProduct - it works with v7, but seems to fail with v8 (using same settings) - probably only needs a minor tweak to make it work with v8.

there are also at least two commercial options in Marketplace if you want to throw money at an off-the-shelf solution.

Link to comment
Share on other sites

1 minute ago, REDOUANE said:

but i want it just in cart not for the user, i know that there a product limit for customer, but i want it for session 

Kian's hook would cover both new and existing users, and they can be treated differently... I assume the same would apply to the commercial solutions too.

Link to comment
Share on other sites

1 hour ago, REDOUANE said:

Is there a way to get a list of products IDs that we have in cart and put them in javascript file ?

I take it you still can't get the hook working ?

the line below from Kian's hook should give you an array (list) of products in the cart...

$productsInCart = array_column($_SESSION['cart']['products'], 'pid');
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.

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