How to conditionaly show add to cart button?

So, I am making a online market place and set up the database, i have cart item and cart as two seperate but linked database. The problem i am facing is how to conditionally show ADD TO CART button by checking these conditions

  1. whether cart items contains the product i am adding
  2. whether the qty is greater than 0 of that item.

Also like while setting up the workflow - that do a search for this and then that…that flow never ends…it keeps going on!!