Set notification if is two product category in cart

Quickly, I thought about that :

(but it’s not my best! Maybe I’ll come rewrite a more thoughtful code sometimes but for now, this code’ll work)

add_action( 'woocommerce_before_cart', 'webroom_check_if_product_category_is_in_cart' );
function webroom_check_if_product_category_is_in_cart() {

    $cat1_in_cart = false;
    $cat2_in_cart = false;

    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

        if ( has_term( 'cat1', 'product_cat', $cart_item['product_id'] ) ) {
            $cat1_in_cart = true;
        } elseif(has_term( 'cat2', 'product_cat', $cart_item['product_id'] )){
            $cat2_in_cart = true;
        }
    }

    if ($cat1_in_cart === true && $cat2_in_cart === true) {
        $notice="Notification";
        wc_print_notice($notice, 'notice');
    }
}