How can I set a limit to the number of products in the cart of the same category?
Can this also be done with products with for instance the same price?
Thank you very much in advance.
function wpbo_minimum_item_quantity_validation( $passed, $product_id, $quantity, $variation_id, $variations ) {
// Make $woocommerce accessible
global $woocommerce;
// Set a minimum item quantity
$minimum = 10;
// Check if the quantity is smaller than our minimum value
if ( $quantity < $minimum ) {
// Get the product title for the error statement
$product = get_product( $product_id );
$product_title = $product->post->post_title;
// Add the error
$woocommerce->add_error( sprintf( "You must add a minimum of %s %s's to your cart to proceed." , $minimum, $product_title ) );
// If the quantity is 10 or above return true
} else {
return true;
}
}