I found this great snippet from this website
The following is the function to check if a specific product exists in cart:
function woo_in_ca
Maybe something simpler, first we get product ids in cart :
$product_ids = array_merge(
wp_list_pluck(WC()->cart->get_cart_contents(), 'variation_id'),
wp_list_pluck(WC()->cart->get_cart_contents(), 'product_id')
);
Now if you want to check one product just simply use in_array function :
in_array(123, $product_ids);
and for more than one product:
array_intersect([123, 345, 567], $product_ids);