Hi,
WooCommerce uses a default stock quantity of 1 as the minimum because it typically deals with whole, discrete products. However, you can change this behavior by using a filter to set the minimum stock quantity to 0.1. Here’s how you can do it:
- Access Your Theme’s
functions.php
File:
Log in to your WordPress admin panel, and navigate to “Appearance” > “Theme Editor.” In the theme editor, look for your theme’s functions.php
file, typically located under the theme’s root directory.
- Add Custom Code:
Inside the functions.php
file, add the following code:
add_filter('woocommerce_product_is_in_stock', 'change_minimum_stock_quantity', 10, 2);
function change_minimum_stock_quantity($is_in_stock, $product) {
// Set your desired minimum stock quantity here (e.g., 0.1).
$minimum_stock_quantity = 0.1;
// Check if the product's stock quantity is less than the minimum.
if ($product->get_stock_quantity() < $minimum_stock_quantity) {
$is_in_stock = true;
}
return $is_in_stock;
}
In this code, the woocommerce_product_is_in_stock
filter is used to check if a product is in stock. If a product’s stock quantity is less than your specified $minimum_stock_quantity
, it will be considered in stock.
- Save Changes:
After adding the code, save the functions.php
file.
- Test:
You can now set your product stock to decimal values like 0.8, and it should be considered in stock if it’s greater than or equal to 0.1.
Please note that modifying your theme files involves working with code, so make sure to create a backup of your website before making any changes. If your theme receives updates, you may need to reapply this change. Consider using a child theme to maintain customizations through theme updates.