Customise Woocommerce message when discount rules coupon is applied working product based

Customize WooCommerce message when discount rules coupons are applied based on product performance.

add_filter('woocommerce_coupon_message', function ($msg, $msg_code, $coupon){
    global $woocommerce;
    $product_ids = array(885,967,971,975,886,968,970,974); // Replace with your condition product IDs
    $products_in_cart = false;

    foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
        if ( in_array( $cart_item['product_id'], $product_ids ) ) {
            $products_in_cart = true;
            break; // Exit the loop if any product is found
        }
    }

    if(!empty($coupon)){
        if(method_exists($coupon, 'get_code')){
            $applicable_coupons = array('23x02-nf45147'); //coupon name in lowercase 
            $coupon_code = strtolower($coupon->get_code()); // Applied coupon code in lowercase
            //DO THE PROCESS FOR CHECKING THE CONDITION MATCHES OR NOT
            if(in_array($coupon_code, $applicable_coupons) && $products_in_cart === false){
                $msg = ''; //YOU CAN CUSTOMIZE THE MESSAGE HERE
            }
        }
    }
    return $msg;
} , 10, 3);