I want on woocommerce to prevent user to add in cart quantity like 2, 3, 4.. The quantity need to be multiply of 7. For example quantity when I’m adding a product need to be 7, 14, 21.. etc.

Bellow is what i’ve tried

function add_the_date_validation() { 
$minimum = 7;
    if (WC()->cart->get_cart_contents_count() % $minimum != 0)
    {
//      wc_clear_notices();
        wc_add_notice(sprintf('You must have an order with a minimum of %s to place your order.', $minimum), 'error');
    }
}
add_action( 'woocommerce_after_add_to_cart_button', 'add_the_date_validation');

But here is checking the total from cart..I want to stop a user to put in cart if the quantity it’s not a multiple of 7.

Read more here: On add to cart check quantity on grouped products


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: