Actually, I am trying to set a limit for adding to cart for some product ids based on product attribute.
What i've done is:
add_action( 'woocommerce_add_to_cart_validation', 'max_add_to_cart', 10, 2 );
function max_add_to_cart( $cart_item_key, $product_id ) {
$product = wc_get_product( $product_id );
$maxqty = $product->get_attribute('quantite_max');
$nbcart = get_item_qty_cart($product_id);
if (!empty($maxqty) && $maxqty <= $nbcart) {
wc_add_notice("cant have more than " . " {$maxqty} x {$product->get_title()} in cart.", 'error');
return false;
}
return true;
}
It works in a loop, but on the product page, it doesn't take into account quantity input.
Is there a way to get quantity add input in my function?