WooCommerce Minimum Quantity Step
WooCommerce plugin to set minimum steps for quantity field
by Robbert Vermeulen · github.com/robbertvermeulen/wc-minimum-quantity-step · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/robbertvermeulen/wc-minimum-quantity-step/archive/refs/heads/claude%2Fwoocommerce-quantity-step-plugin-011CUtJfZgDTe7LvB9yjvZbR.zipA WooCommerce plugin that allows you to set minimum/maximum quantities and quantity steps per product, while keeping the default quantity at 1 for Google Shopping compliance.
Features
- ✅ Set custom quantity steps per product (e.g., must order in multiples of 2, 3, 5, etc.)
- ✅ Set minimum and maximum quantities per product and variation
- ✅ Default quantity remains at 1 (compliant with Google Shopping requirements)
- ✅ Real-time JavaScript validation with user-friendly error messages
- ✅ Server-side PHP validation for add-to-cart and cart updates
- ✅ Cart quantity checking (validates existing + new quantity)
- ✅ Variable products: choose if parent max applies to all variations combined or per variation
- ✅ Dynamic step adjustment after valid quantity selection
- ✅ Works with both simple and variable products
- ✅ Compatible with most WooCommerce themes and custom quantity buttons
- ✅ Universal implementation using standard WooCommerce hooks and classes
- ✅ Lightweight and performance-optimized
- ✅ Multilingual ready with translation support
The Problem This Plugin Solves
When running Google Shopping campaigns, products must show a price that matches the minimum order quantity. If a product costs €59 but must be ordered in sets of 2, setting the default quantity to 2 would cause the product to show as €118 in shopping feeds, leading to campaign rejection.
This plugin solves this by:
- Keeping the default quantity at 1 (price shows correctly in feeds)
- Preventing checkout with invalid quantities
- Guiding users to select valid quantities (multiples of your chosen step)
Requirements
- WordPress 5.8 or higher
- WooCommerce 5.0 or higher
- PHP 7.4 or higher
Installation
Method 1: Manual Installation
- Download or clone this repository
- Upload the
wc-minimum-quantity-stepfolder to/wp-content/plugins/ - Activate the plugin through the 'Plugins' menu in WordPress
- Navigate to any product edit page to configure quantity steps
Method 2: Via WordPress Admin
- Go to Plugins > Add New
- Click "Upload Plugin"
- Choose the plugin ZIP file
- Click "Install Now"
- Activate the plugin
Usage
Setting Up Quantity Restrictions for a Product
- Go to Products in your WordPress admin
- Edit any product (simple or variable)
- Scroll to the Product Data section
- Click on the Inventory tab
- Find the Quantity Restrictions section with the following fields:
- Minimum Quantity Step: Multiples in which the product must be ordered (e.g.,
2for pairs) - Minimum Quantity: Minimum number of items per order (optional)
- Maximum Quantity: Maximum number of items per order (optional)
- Minimum Quantity Step: Multiples in which the product must be ordered (e.g.,
- Enter your desired values (all fields are optional)
- Click Update to save
Setting Up Variable Products
For variable products, you have two options:
Option 1: Apply parent restrictions to all variations
- Set restrictions on the parent product level
- Check the box "Apply these restrictions to all variations"
- All variations will use the parent restrictions
Option 2: Individual variation restrictions (default)
- Leave the checkbox unchecked
- Set restrictions on each variation individually
- When parent max is set, it applies to ALL variations combined as a total limit
Example Scenarios
Scenario 1: Product Must Be Ordered in Pairs
Setting:
- Minimum Quantity Step =
2
Behavior:
- Default quantity shows: 1
- Customer tries to add 1: ❌ Error message appears
- Customer changes to 2: ✅ Can add to cart
- Quantity field now steps by 2 (2, 4, 6, 8...)
Scenario 2: Product with Min and Max Limits
Setting:
- Minimum Quantity =
3 - Maximum Quantity =
10
Behavior:
- Customer tries to add 1 or 2: ❌ Error - minimum 3 required
- Customer tries to add 3-10: ✅ Allowed
- Customer tries to add 11: ❌ Error - maximum 10 allowed
- Cart checks include existing quantities
Scenario 3: Variable Product with Total Family Limit
Setting (Parent product):
- Maximum Quantity =
6 - Checkbox unchecked (default)
Setting (Variations):
- Variation A: Maximum Quantity =
1 - Variation B: Maximum Quantity =
1
Behavior:
- Customer adds 1x Variation A: ✅ Allowed
- Customer tries to add another Variation A: ❌ Max 1 of this variation
- Customer adds 1x Variation B: ✅ Allowed (total now 2)
- Customer can add max 6 items total across all variations combined
- Once 6 total items in cart: ❌ Parent max reached
Scenario 4: No Restrictions
Setting: Leave all fields empty
Behavior:
- Works as standard WooCommerce (any quantity allowed)
How It Works
Frontend Validation (JavaScript)
The plugin uses JavaScript to provide instant feedback:
- On Load: Removes HTML5 step validation, sets input mode to numeric
- On Change: Validates quantity against step, min, and max requirements
- Invalid Quantity: Shows validation message (color #F9BB3F), prevents add to cart
- Valid Quantity: Hides message, adjusts step attribute for easier selection
- Plus/Minus Buttons: Automatically validated after click
- Scroll Behavior: Only scrolls to message if it's outside viewport
Backend Validation (PHP)
Server-side validation ensures security:
- Add to Cart: Validates before adding item (checks existing cart quantity + new quantity)
- Cart Update: Validates when changing quantities in cart
- Checkout: Validates all items at checkout
- Variable Products: Validates parent max as total for all variations (when checkbox unchecked)
- Invalid Quantity: Shows WooCommerce error notice, prevents action
Compatibility
The plugin works with:
- Standard WooCommerce quantity inputs
- Custom theme quantity buttons
- Variable products with multiple variations
- AJAX add to cart
- Plus/minus quantity buttons
- Mobile and desktop interfaces
Technical Implementation
Hooks Used
Admin Hooks:
woocommerce_product_options_inventory_product_data- Add custom fields to simple productswoocommerce_process_product_meta- Save product meta fields (with array detection to prevent parent overwrite)woocommerce_variation_options_pricing- Add custom fields to variationswoocommerce_save_product_variation- Save variation meta fields
Frontend Hooks:
wp_enqueue_scripts- Load assetswoocommerce_available_variation- Add restrictions to variation datawoocommerce_add_to_cart_validation- Validate add to cart (5 params including variation_id)woocommerce_update_cart_validation- Validate cart updateswoocommerce_checkout_process- Validate quantities at checkout
AJAX Endpoints:
wp_ajax_get_quantity_step- Get quantity step for productwp_ajax_nopriv_get_quantity_step- Public endpoint for non-logged in users
JavaScript Events
change- Quantity input changesclick- Add to cart button, plus/minus buttonsfound_variation- Variable product variation selectedreset_data- Variable product variation reset
File Structure
wc-minimum-quantity-step/
├── assets/
│ ├── css/
│ │ └── frontend.css # Validation message styling
│ └── js/
│ └── frontend.js # Client-side validation logic
├── languages/
│ ├── wc-minimum-quantity-step-{locale}.po # Translation files
│ ├── wc-minimum-quantity-step-{locale}.mo # Compiled translations
│ └── wc-minimum-quantity-step.pot # Translation template
├── wc-minimum-quantity-step.php # Main plugin file
└── README.md
Key Features Implementation
Cart Quantity Checking:
get_cart_quantity_for_item()- Gets existing cart quantity for specific product/variationget_cart_quantity_for_product_family()- Gets total quantity for all variations of a parent product- Validates existing quantity + new quantity against limits
Variable Product Family Limits:
- When checkbox unchecked: Parent max applies to ALL variations combined
- When checkbox checked: Parent restrictions apply per individual variation
- Array detection in POST data prevents parent settings from being overwritten when saving variations
Customization
Changing Validation Messages
You can customize the validation messages using WordPress filters or by editing the language files:
Option 1: Using gettext filter
add_filter('gettext', 'custom_wcmqs_error_message', 10, 3);
function custom_wcmqs_error_message($translation, $text, $domain) {
if ($domain === 'wc-minimum-quantity-step') {
if (strpos($text, 'must be ordered in multiples') !== false) {
return 'Custom message with %d placeholder';
}
}
return $translation;
}
Option 2: Edit language files
- Create your own translation files in the
languages/directory - Use tools like Poedit to edit
.pofiles - Compile to
.mofiles after changes - Load your translations using WordPress i18n system
Styling the Validation Message
Add custom CSS to your theme:
.wcmqs-validation-message {
color: #your-color !important;
font-size: 1em !important;
font-weight: bold !important;
}
Default styling uses color #F9BB3F for validation messages.
Adding Custom Validation Logic
You can hook into the validation filters:
add_filter('woocommerce_add_to_cart_validation', 'my_custom_validation', 20, 5);
function my_custom_validation($passed, $product_id, $quantity, $variation_id, $variations) {
// Your custom logic here
// Note: Use $variation_id when available (for variable products)
$actual_product_id = $variation_id > 0 ? $variation_id : $product_id;
return $passed;
}
Troubleshooting
Issue: Validation Not Working
Solutions:
- Clear browser cache and hard refresh (Ctrl+Shift+R)
- Check browser console for JavaScript errors
- Ensure WooCommerce is up to date
- Disable other plugins to check for conflicts
Issue: Parent Product Settings Get Overwritten When Saving Variations
Solutions:
- This was fixed in version 1.2.3
- Update to the latest version
- The plugin now detects array POST data to prevent parent overwrites
Issue: Cart Quantity Not Being Checked
Solutions:
- This feature was added in version 1.2.0
- Update to the latest version
- The plugin now checks existing cart quantity + new quantity
Issue: Validation Message Not Showing
Solutions:
- Check if
.wcmqs-validation-messageclass is styled in your theme - Ensure JavaScript is enabled in browser
- Check for JavaScript conflicts in browser console
Issue: Variable Products - Parent Max Not Working Correctly
Solutions:
- Check the "Apply these restrictions to all variations" checkbox:
- Unchecked (default): Parent max applies to ALL variations combined as total
- Checked: Parent restrictions apply per individual variation
- Ensure you're using version 1.2.0 or later
Issue: Translation Not Working
Solutions:
- Ensure your translation
.mofile exists in thelanguages/directory - Check that the file naming convention is correct:
wc-minimum-quantity-step-{locale}.mo - Set your WordPress language in Settings > General
- Clear any translation caches
- Use WordPress translation plugins like Loco Translate for easier management
Support
For bug reports and feature requests, please use the GitHub Issues page.
Changelog
1.2.3 - 2024-11-11
- Fixed: Parent product settings being overwritten when saving variations
- Improved: Array detection in POST data to distinguish variation saves from parent saves
1.2.2 - 2024-11-11
- Attempted fix for parent settings overwrite issue (replaced by 1.2.3)
1.2.1 - 2024-11-11
- Fixed: Variation ID not being used in add-to-cart validation
- Improved: Now properly uses variation_id parameter from WooCommerce hook
1.2.0 - 2024-11-11
- Added: Cart quantity checking (existing + new quantity validation)
- Added: Parent max validation for variable products (applies to all variations combined when checkbox OFF)
- Added: Checkbox to apply parent restrictions to all variations
- Improved: Better validation messaging with cart context
1.1.0 - 2024-11-11
- Added: Minimum and Maximum quantity fields (in addition to step)
- Added: Multilingual support with translation-ready architecture
- Changed: Validation message styling to simple text with customizable color
- Changed: All admin fields are now optional (can be left empty)
- Added: Checkout validation
- Added: Scroll behavior only when message is outside viewport
1.0.0 - 2024-11-07
- Initial release
- Simple and variable product support
- JavaScript and PHP validation
- Dynamic step adjustment
- Google Shopping compliance
License
This plugin is licensed under the GPL v2 or later.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Credits
Developed by Robbert Vermeulen
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request