Are you looking for an easy way to edit the minimum or maximum order quantity? You may want to introduce this feature in your WooCommerce store to control customer purchases. In this post I want to show you how to set up WooCommerce minimum or maximum order quantity.
There are many plugins available in the WordPress repository that can help you set the minimum or maximum order quantity. However, some plugins may conflict with your theme and they need to be updated regularly.
WooCommerce Minimum or Maximum Order Quantity
In this brief tutorial, we will share with you a custom solution to edit the minimum or maximum order quantity using PHP. We recommend using a child theme so that your changes are not lost during an update.
The solution we will share physically restricts the number of each product that customers can add to the cart.
Let us look at how you can achieve this.
Steps to Set the Minimum, Maximum, and Start Value to Cart Quantity in the WooCommerce Single Product Page and Cart Page
Here are the steps you need to follow:
- Log into your WordPress site and access the Dashboard as the admin user.
- From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will set the minimum, maximum, and start value to cart quantity.
- Add the following code to the php file:
* Code snippet: Set the Minimum, Maximum, and Start Value to Cart Quantity
*/
add_filter( ‘woocommerce_quantity_input_args’, ‘njengah_woocommerce_quantity_changes’, 10, 2 );
function njengah_woocommerce_quantity_changes( $args, $product ) {
if ( ! is_cart() ) {
$args[‘input_value’] = 4; // Start from this value (default = 1)
$args[‘max_value’] = 10; // Max quantity (default = -1)
$args[‘min_value’] = 4; // Min quantity (default = 0)
$args[‘step’] = 2; // Increment/decrement by this value (default = 1)
} else {
// Cart’s "min_value" is already 0 and we don’t need "input_value"
$args[‘max_value’] = 10; // Max quantity (default = -1)
$args[‘step’] = 2; // Increment/decrement by this value (default = 0)
// COMMENT OUT FOLLOWING IF STEP < MIN_VALUE
// $args[‘min_value’] = 4; // Min quantity (default = 0)
}
return $args;
}
[/php]- In our example, we have set the minimum quantity to 4 and the maximum quantity to 10. You should edit out that section depending on your requirements. This is the outcome:
- If you want to set the minimum quantity for variations, add the following code to the php file:
* Code snippet: Minimum Add to Cart Quantity for Variations for WooCommerce
*/
add_filter( ‘woocommerce_available_variation’, ‘njengah_woocommerce_quantity_min_variation’, 9999, 3 );
function njengah_woocommerce_quantity_min_variation( $args, $product, $variation ) {
$args[‘min_qty’] = 5;
return $args;
}
[/php]
Wrapping Up
WooCommerce does not have the feature to set a minimum and maximum quantity limit when ordering a product.
However, we have shared how you can easily do that using PHP.
Now you are able to set the minimum or maximum order quantity in your WooCommerce store. The solutions we have shared have been tested on the Storefront theme.
It is important to place PHP snippets at the bottom of your child theme functions.php file. You should be very careful when editing this file.
If you want a free plugin that will help you to add the feature to your WooCommerce store, Min and Max Quantity for WooCommerce is the best choice for you.
Similar Articles
- How to Hide Tags In Storefront Theme WooCommerce
- How to Disable Payment Method for Specific Category
- How to Hide Add to Cart Button in WooCommerce
- Hide or Remove the Quantity Field from WooCommerce Product Page
- How to Add Product Image WooCommerce Checkout Page
- How to Create Coupon In WooCommerce
- How to Create WooCommerce Custom Shop Page
- How to Add Currency to WooCommerce [Custom Currency]
- How to Create Custom Order Received Page WooCommerce
- WooCommerce Mobile Checkout Optimization Quick Guide
- How to Add Custom WooCommerce Payment Icons Checkout Page
- WooCommerce Checkout Optimization Quick Guide
- WooCommerce Difference Between PayPal and PayPal Checkout
- How to Change WooCommerce Checkout Page Title
- How to Customize Storefront Checkout Page
- How to Change WooCommerce Thank You Page
- How to Set Up WooCommerce Bitcoin Checkout
- How to Hide Category From Shop Page WooCommerce