Show wc_add_notice only one time

I have the next code

add_action( 'woocommerce_add_to_cart_validation', 'custom_add_to_cart_validation', 10, 3 );
function custom_add_to_cart_validation( $passed, $product_id, $quantity) {
    $_product = wc_get_product( $product_id );
    $quantity_total = (array_sum($_POST['quantity']));
    // echo $quantity_total;

    if ($quantity_total % 2 != 0) {
        wc_add_notice( __( 'Multiple of 2 required quantity.', 'woocommerce' ), 'error' );
        $passed = false;
        $passed = true;

    return $passed;

I have a grouped product with many items in & for each product if the condition it’s true i’m getting this notice..but I want to display it just one time. Now is displayed error message for each input .. from page of each product, what I want is to display just a single time.

Read more here: Show wc_add_notice only one time

Leave a Reply

Your email address will not be published. Required fields are marked *