See I have restructured your code with few changes, I would request you to give it a try
add_action( 'woocommerce_check_cart_items', 'check_total' );
function check_total() {
// Only run in the Cart or Checkout pages
if( is_cart() || is_checkout() ) {
global $woocommerce, $product;
$total_quantity = 0;
$display_notice = 1;
$i = 0;
//loop through all cart products
foreach ( $woocommerce->cart->cart_contents as $product ) {
// See if any product is from the cuvees category or not
if ( has_term( 'cuvees', 'product_cat', $product['product_id'] )) {
$total_quantity += $product['quantity'];
}
}
// Set up the acceptable totals and loop through them so we don't have an ugly if statement below.
$acceptable_totals = array(1, 2, 3, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 72, 96, 120);
foreach($acceptable_totals as $total_check) {
if ( $total_check == $total_quantity ) { $display_notice = 0; }
}
foreach ( $woocommerce->cart->cart_contents as $product ) {
if ( has_term( 'cuvees', 'product_cat', $product['product_id'] ) ) {
if( $display_notice == 1 && $i == 0 ) {
// Display our error message
wc_add_notice( sprintf( '<h5 style="letter-spacing:0.5px;color:white;text-align:center;">/!\ Une commande de %d bouteilles n'est pas possible ! /!\ </h5><br /> <br /><p style="text-align:center;"> L'envoi n'est possible que pour 1 | 2 | 3 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 | 72 | 96 | 120 et plus bouteilles.</p>', $total_quantity),
'error' );
}
$i++;
}
}
}
}