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;
    }
    else{
        $passed = true;
    }var_dump($quantity_total);

    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


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: