Here’s an interesting scenario that came up recently with a client – this client has an iconic following and is famous for their seasoning. Their selling strategy is to only offer their products and services through their own channels and specifically does not include Amazon. Unfortunately, others saw this as an opportunity to buy the seasoning and resell it on Amazon by marking up the price. Because of the gray area of reselling products on Amazon, there is not a whole lot that my client could legally do. What’s worse, many (more than half) of the resellers who purchased the seasoning to resell were using fraudulent credit cards in order to reap even more profit. My client would not learn that the transaction was fraudulent until about 30 days later when the bank marked it as a charge-back. So my client was not only out the bulk order of seasoning but was also out the money. They asked me to find a way to limit the quantity of each item to 10 per transaction. That way, the fraudster would have to pay for the shipping for the purchase of every 10 seasonings. After looking into it, it’s a fairly simple snippet of code that can be applied to as many products as you would like in a simple array.
Code Snippet for Limiting Item Quantity Per Order
Add the snippet below to the functions.php file in the child theme (at your own risk).
• Replace Product ID numbers and max number per order in the array. You can add as many products as you would like.
• Make sure to let the customer know in the product description somewhere that there is a limit of 10 items per order so they are not surprised when the error pops up.
• Refresh and test the code by trying to add at least 11 of the items included in this code to your cart.
add_filter('woocommerce_add_to_cart_validation', 'custom_max_qty_limit_multiple_products', 10, 3);
function custom_max_qty_limit_multiple_products($passed, $product_id, $quantity) {
$max_qty_per_product = [
123 => 5, // Product ID 123 - max 5 per order
456 => 3, // Product ID 456 - max 3 per order
789 => 2, // Product ID 789 - max 2 per order
];
if (array_key_exists($product_id, $max_qty_per_product) && $quantity > $max_qty_per_product[$product_id]) {
wc_add_notice(__('You can only purchase up to ' . $max_qty_per_product[$product_id] . ' of this item per order.'), 'error');
return false;
}
return $passed;
}
Once refreshed, test the snippet by adding at least 11 items to your cart and you should see a nice little error message appear stating that ‘You can only purchase up to 10 of this item per order.’ It will not add the items to the cart and the buyer is hopefully discouraged from trying to purchase in bulk with a fraudulent credit card.

Are there customers who are legitimate that may purchase more than 10 at a time? Sure but they are few and far between and the customer may still call to purchase more than 10 if they really want to. Most fraudsters will not call to place an order because they can’t hide behind a screen.
Have you or anyone you know ever had this problem? If so, what did you do to remedy it? We would love to hear from you!