| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | public function __construct() { |
| 27 | 27 | add_action( 'woocommerce_product_set_stock', array( $this, 'product_set_stock' ) ); |
| 28 | 28 | add_action( 'woocommerce_variation_set_stock', array( $this, 'product_set_stock' ) ); |
| 29 | 29 | |
| 30 | - $pos_only_products = woocommerce_pos_get_settings( 'general', 'pos_only_products' ); | |
| 30 | + $pos_only_products = Settings::instance()->pos_only_products_enabled(); | |
| 31 | 31 | |
| 32 | 32 | if ( $pos_only_products ) { |
| 33 | 33 | add_action( 'pre_get_posts', array( $this, 'hide_pos_only_products' ) ); |
| 34 | 34 | add_filter( 'woocommerce_variation_is_visible', array( $this, 'hide_pos_only_variations' ), 10, 4 ); |
| @@ -44,10 +44,10 @@ | ||
| 44 | 44 | * Allow decimal quantities for products and variations. |
| 45 | 45 | * |
| 46 | 46 | * @TODO - this will affect the online store as well, should I make it POS only? |
| 47 | 47 | */ |
| 48 | - $allow_decimal_quantities = woocommerce_pos_get_settings( 'general', 'decimal_qty' ); | |
| 49 | - if ( \is_bool( $allow_decimal_quantities ) && $allow_decimal_quantities ) { | |
| 48 | + $allow_decimal_quantities = Settings::instance()->decimal_qty_enabled(); | |
| 49 | + if ( $allow_decimal_quantities ) { | |
| 50 | 50 | remove_filter( 'woocommerce_stock_amount', 'intval' ); |
| 51 | 51 | add_filter( 'woocommerce_stock_amount', 'floatval' ); |
| 52 | 52 | add_action( 'woocommerce_before_product_object_save', array( $this, 'save_decimal_quantities' ) ); |
| 53 | 53 | } |
| @@ -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'; |