diff --git a/woo-business-central/includes/class-wbc-product-sync.php b/woo-business-central/includes/class-wbc-product-sync.php index 43f9983..eb9af90 100644 --- a/woo-business-central/includes/class-wbc-product-sync.php +++ b/woo-business-central/includes/class-wbc-product-sync.php @@ -349,6 +349,7 @@ class WBC_Product_Sync { try { $product->set_sku( $sku ); $product->set_status( get_option( 'wbc_new_product_status', 'draft' ) === 'publish' ? 'publish' : 'draft' ); + $product->set_manage_stock( true ); $product->save(); } catch ( Exception $e ) { WBC_Logger::error( 'ProductSync', 'Failed to create WooCommerce product from BC item', array( @@ -561,9 +562,16 @@ class WBC_Product_Sync { if ( get_option( 'wbc_enable_stock_sync', 'yes' ) === 'yes' ) { $stock = isset( $item['inventory'] ) ? (float) $item['inventory'] : 0; $current_stock = (float) $product->get_stock_quantity(); + $needs_manage_stock = ! $product->get_manage_stock(); - if ( $stock !== $current_stock ) { - if ( ! $product->get_manage_stock() ) { + // Also run this when stock management isn't on yet, even if the + // (defaulted, unmanaged) current value happens to already equal + // the BC value - otherwise a brand-new product with 0 BC stock + // never gets manage_stock enabled (0 !== 0 looks like "no + // change") and is left at WooCommerce's default stock_status + // of "instock" with no quantity tracked at all. + if ( $stock !== $current_stock || $needs_manage_stock ) { + if ( $needs_manage_stock ) { $product->set_manage_stock( true ); }