Control access to buy products We would like to be able to restrict access to buy products.


A product could be members-only
Users who are already members should be prevented from buying membership again until near expiry.


If there is no access to buy, the "add to cart" button should not be shown.  There also needs to be a check during checkout, for example in case the a member added a membership to the cart as anonymous then logged in, they still should not be able to buy membership.

We don't want to restrict access to view products.  Non-members should be able to see the benefits of membership, and what extra things they could buy.  The price should still be visible for products that cannot be bought (so we can't hide the entire "Add to Cart" form as that's where the price comes from).

Please can someone explain how to achieve this?
I believe that good start is to implement EventSubscriber listening on ProductEvents::FILTER_VARIATIONS event. It was introduced to filter out some product variations based on different aspects, such as stock, date, etc.