I have a requirement in my website where the customer can buy a certain product only once. If they try to buy that again it should throw an error saying cannot purchase this again.
Please help me on this.
I have a requirement in my website where the customer can buy a certain product only once. If they try to buy that again it should throw an error saying cannot purchase this again.
Please help me on this.
2
Answers
If it is only one or few products like that – the best way in my opinion is to add attribute to customer and change it after product is purchased.
Thanks for your question…
Solution:-
1- You’ve to create product attribute as Yes/No & by default, it’ll be No.you’ve to select as Yes for the product which you want to avail purchase only once.
2- If a customer is logged in, then during Add to Cart if a product can purchase only once for a customer then before adding to cart(use observer here) you’ve to check if a customer already purchases this item if yes then you’ve to avoid
Add to Cart else customer can add this to cart.
3- If a customer is not logged in, in this case, it depends on you.
There may be 2 cases:-
a- Simply customer can be added to cart any item & after login, if a customer has added the restricted item(only once purchase) then you’ve to remove the restricted item from the cart if already purchased else vice versa.
b- OR you don’t allow to Add To Cart(by an observer) restricted item if a customer is not logged in.
Hope it’ll resolve your problem.