Zend certified PHP/Magento developer

Check if product is already in cart

Magento 2.3.3

Store is strictly downloadable mp3 products. Thus max quantity for each product is one (adding more than one would not make sense). I’d like to check if a product is already in the cart, and if so, I’ll hide the Add to Cart button.

(Current default behavior is that if the product is already in the cart, clicking the button sends you to the product page with an error message. I’d like to skip this.)

I’ve found this, but it doesn’t work:

How to check whether a product is in the cart?

The $productInfo array in the above example is empty, even when there are items in the cart.

This also did not help me: how to check if product is already in cart