Introduction: When managing a WooCommerce website, you may need to set different minimum order quantities for different products. This need is especially common in wholesale or bulk-transaction type e-commerce sites. While it's possible to use a plugin to simplify this process, if you'd like to have more direct control over these settings, implementing them through custom code may be a good option. This tutorial will walk you through how to manually set custom minimum order quantities for each WooCommerce product.
![图片[1]-详细教程:在 WooCommerce 中为每个产品设置自定义的最小起订量-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2023/12/2023121808290337-1024x585.png)
Preparation:
- Make sure you have access to the WordPress website backend.
- Before making changes, it is recommended that you back up your website, especially the
functions.phpDocumentation.
Step 1: Access the functions.php file In the WordPress backend, navigate to your theme editor and find the functions.php file. You can also edit this file by accessing your server via FTP.
![图片[2]-详细教程:在 WooCommerce 中为每个产品设置自定义的最小起订量-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2023/12/2023121808300711-1024x585.png)
Step 2: Add Custom Code exist functions.php At the end of the file, paste the following code:
function set_custom_min_order_quantities( $min, $product ) {
$product_min_quantities = array(
30 => 10, // Example: Product ID 30 has a minimum order quantity of 10.
42 => 20, // Example: Product ID 42 has a minimum order quantity of 20
// You can continue to add more products and quantities
);
if ( array_key_exists( $product->get_id(), $product_min_quantities ) ) {
return $product_min_quantities[ $product->get_id() ];
}
return $min; // if not specifically set, return the default minimum order quantity
}
add_filter( 'woocommerce_quantity_input_min', 'set_custom_min_order_quantity', 10, 2 );
add_filter( 'woocommerce_quantity_input_min', 'set_global_minimum_order_quantity' );
function set_global_minimum_order_quantity( $min ) {
return 50; // Set the minimum order quantity for all products to 50
}
This code can be copied and used directly, you can set the minimum order quantity in batch, currently it is a variable of 50 minimum orders, you can change it according to your needs!Step 3: Customize the minimum order quantity for the product In the code above, the$product_min_quantities The array defines the product ID and the corresponding minimum order quantity. Modify this array according to your own product ID and required minimum order quantity.
![图片[3]-详细教程:在 WooCommerce 中为每个产品设置自定义的最小起订量-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2023/12/2023121808313469-1024x585.png)
Step 4: Save and Test save (a file etc) (computing) functions.php After the file, go to your website and test each product. Make sure that the minimum order quantity for each product is displayed according to your settings.
Conclusion: By following the steps above, you can set a custom minimum order quantity for each product on your WooCommerce site. Keep in mind that each time you change the minimum order quantity, you will need to update the functions.php code in the file. If you have a wide variety of products or frequently need to adjust minimum order quantities, considering a plugin or custom development may be a more efficient solution.
![图片[4]-详细教程:在 WooCommerce 中为每个产品设置自定义的最小起订量-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/uploads/2023/12/2023121808315154-1024x585.png)
Link to this article:https://www.361sale.com/en/5456/The article is copyrighted and must be reproduced with attribution.



















![表情[wozuimei]-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/themes/zibll/img/smilies/wozuimei.gif)
![表情[baoquan]-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/themes/zibll/img/smilies/baoquan.gif)

No comments