WC_Cart::find_product_in_cart()publicWC 1.0

Check if product is in the cart and return cart item key.

Cart item key will be unique based on the item and its properties, such as variations.

{} It's a method of the class: WC_Cart{}

No Hooks.

Return

String. cart item key

Usage

$WC_Cart = new WC_Cart();
$WC_Cart->find_product_in_cart( $cart_id );
$cart_id(mixed)
id of product to find in the cart.
Default: false

Code of WC_Cart::find_product_in_cart() WC 6.7.0

public function find_product_in_cart( $cart_id = false ) {
	if ( false !== $cart_id ) {
		if ( is_array( $this->cart_contents ) && isset( $this->cart_contents[ $cart_id ] ) ) {
			return $cart_id;
		}
	}
	return '';
}