cart->is_empty(); switch ( $display_rule ) { case 'hasProducts': return ! $is_cart_empty; case 'isEmpty': return $is_cart_empty; case 'hasSpecificProduct': return $this->_has_specific_product_in_cart( $products_ids ); case 'doesNotHaveSpecificProduct': return ! $this->_has_specific_product_in_cart( $products_ids ); default: return false; } } /** * Checks presence of specified products in the Cart. * * @param Array $products_ids Array of products IDs to check against the Cart's products. * @return boolean Indicating the presence of specified products in the Cart. */ protected function _has_specific_product_in_cart( $products_ids ) { $has_specific_product = false; if ( ! WC()->cart->is_empty() ) { foreach ( WC()->cart->get_cart() as $cart_item ) { $cart_item_ids = [ $cart_item['product_id'], $cart_item['variation_id'] ]; if ( array_intersect( $products_ids, $cart_item_ids ) ) { $has_specific_product = true; break; } } } return $has_specific_product; } }