| @@ -208,11 +208,11 @@ | ||
| 208 | 208 | * |
| 209 | 209 | * @param WC_Product $product Product. |
| 210 | 210 | */ |
| 211 | 211 | public function save_decimal_quantities( WC_Product $product ): void { |
| 212 | + // Without stock management there is no quantity to derive a status from; | |
| 213 | + // WooCommerce respects the manually chosen stock status, so leave it untouched. | |
| 212 | 214 | if ( ! $product->get_manage_stock() ) { |
| 213 | - $product->set_stock_status( 'instock' ); | |
| 214 | - | |
| 215 | 215 | return; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | $stock_quantity = $product->get_stock_quantity(); |
| @@ -217,10 +217,12 @@ | ||
| 217 | 217 | |
| 218 | 218 | $stock_quantity = $product->get_stock_quantity(); |
| 219 | 219 | $stock_notification_threshold = absint( get_option( 'woocommerce_notify_no_stock_amount', 0 ) ); |
| 220 | 220 | |
| 221 | - // Adjust the condition to consider stock quantities between 0 and 1 as instock if greater than 0. | |
| 222 | - $stock_is_above_notification_threshold = ( $stock_quantity > 0 && $stock_quantity > $stock_notification_threshold ); | |
| 221 | + // Mirrors WC_Product::validate_props() minus its (int) cast on the stock | |
| 222 | + // quantity, which would truncate fractional stock (e.g. 0.5) to 0 and | |
| 223 | + // mark it out of stock. Re-check against core on WooCommerce updates. | |
| 224 | + $stock_is_above_notification_threshold = ( $stock_quantity > $stock_notification_threshold ); | |
| 223 | 225 | $backorders_are_allowed = ( 'no' !== $product->get_backorders() ); |
| 224 | 226 | |
| 225 | 227 | if ( $stock_is_above_notification_threshold ) { |
| 226 | 228 | $new_stock_status = 'instock'; |