diff --git a/plugins/woocommerce/changelog/fix-revert_set_stock_quantity b/plugins/woocommerce/changelog/fix-revert_set_stock_quantity new file mode 100644 index 00000000000..e421b1565b7 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-revert_set_stock_quantity @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Revert "Set stock quantity value as 0 by default (#48448)" #48863 diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-product.php b/plugins/woocommerce/includes/abstracts/abstract-wc-product.php index fb02e4b0863..9200e884f71 100644 --- a/plugins/woocommerce/includes/abstracts/abstract-wc-product.php +++ b/plugins/woocommerce/includes/abstracts/abstract-wc-product.php @@ -74,7 +74,7 @@ class WC_Product extends WC_Abstract_Legacy_Product { 'tax_status' => 'taxable', 'tax_class' => '', 'manage_stock' => false, - 'stock_quantity' => 0, + 'stock_quantity' => null, 'stock_status' => 'instock', 'backorders' => 'no', 'low_stock_amount' => '', @@ -358,10 +358,10 @@ class WC_Product extends WC_Abstract_Legacy_Product { * Returns number of items available for sale. * * @param string $context What the value is for. Valid values are view and edit. - * @return int + * @return int|null */ public function get_stock_quantity( $context = 'view' ) { - return $this->get_prop( 'stock_quantity', $context ) ?? 0; + return $this->get_prop( 'stock_quantity', $context ); } /** @@ -966,7 +966,7 @@ class WC_Product extends WC_Abstract_Legacy_Product { * @param float|null $quantity Stock quantity. */ public function set_stock_quantity( $quantity ) { - $this->set_prop( 'stock_quantity', '' !== $quantity ? wc_stock_amount( $quantity ) : 0 ); + $this->set_prop( 'stock_quantity', '' !== $quantity ? wc_stock_amount( $quantity ) : null ); } /** diff --git a/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php b/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php index 7ed500c026c..47d51af710c 100644 --- a/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php +++ b/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php @@ -332,7 +332,7 @@ class WC_Meta_Box_Product_Data { $classname = WC_Product_Factory::get_product_classname( $post_id, $product_type ? $product_type : 'simple' ); $product = new $classname( $post_id ); $attributes = self::prepare_attributes(); - $stock = 0; + $stock = null; // Handle stock changes. if ( isset( $_POST['_stock'] ) ) { @@ -483,7 +483,7 @@ class WC_Meta_Box_Product_Data { } $variation_id = absint( $_POST['variable_post_id'][ $i ] ); $variation = wc_get_product_object( 'variation', $variation_id ); - $stock = 0; + $stock = null; // Handle stock changes. if ( isset( $_POST['variable_stock'], $_POST['variable_stock'][ $i ] ) ) { diff --git a/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-inventory.php b/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-inventory.php index fef97ca380e..e14605de6cc 100644 --- a/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-inventory.php +++ b/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-inventory.php @@ -56,7 +56,7 @@ if ( ! defined( 'ABSPATH' ) ) { woocommerce_wp_text_input( array( 'id' => '_stock', - 'value' => wc_stock_amount( $product_object->get_stock_quantity( 'edit' ) ), + 'value' => wc_stock_amount( $product_object->get_stock_quantity( 'edit' ) ?? 1 ), 'label' => __( 'Quantity', 'woocommerce' ), 'desc_tip' => true, 'description' => __( 'Stock quantity. If this is a variable product this value will be used to control stock for all variations, unless you define stock at variation level.', 'woocommerce' ), diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php index 983a95b1ac9..7a6a437c23b 100644 --- a/plugins/woocommerce/includes/class-wc-install.php +++ b/plugins/woocommerce/includes/class-wc-install.php @@ -1640,7 +1640,7 @@ CREATE TABLE {$wpdb->prefix}wc_product_meta_lookup ( `min_price` decimal(19,4) NULL default NULL, `max_price` decimal(19,4) NULL default NULL, `onsale` tinyint(1) NULL default 0, - `stock_quantity` double NULL default 0, + `stock_quantity` double NULL default NULL, `stock_status` varchar(100) NULL default 'instock', `rating_count` bigint(20) NULL default 0, `average_rating` decimal(3,2) NULL default 0.00, diff --git a/plugins/woocommerce/includes/class-wc-product-variation.php b/plugins/woocommerce/includes/class-wc-product-variation.php index d845ad11b6c..83b80fc206c 100644 --- a/plugins/woocommerce/includes/class-wc-product-variation.php +++ b/plugins/woocommerce/includes/class-wc-product-variation.php @@ -329,7 +329,7 @@ class WC_Product_Variation extends WC_Product_Simple { * Returns number of items available for sale. * * @param string $context What the value is for. Valid values are view and edit. - * @return int + * @return int|null */ public function get_stock_quantity( $context = 'view' ) { $value = $this->get_prop( 'stock_quantity', $context ); @@ -338,7 +338,7 @@ class WC_Product_Variation extends WC_Product_Simple { if ( 'view' === $context && 'parent' === $this->get_manage_stock() ) { $value = apply_filters( $this->get_hook_prefix() . 'stock_quantity', $this->parent_data['stock_quantity'], $this ); } - return $value ?? 0; + return $value; } /** diff --git a/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php b/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php index 29128d53f0f..757d404c3df 100644 --- a/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php @@ -1399,12 +1399,12 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da * Uses locking to update the quantity. If the lock is not acquired, change is lost. * * @since 3.0.0 this supports set, increase and decrease. - * @param int $product_id_with_stock Product ID. - * @param int|float $stock_quantity Stock quantity. - * @param string $operation Set, increase and decrease. + * @param int $product_id_with_stock Product ID. + * @param int|float|null $stock_quantity Stock quantity. + * @param string $operation Set, increase and decrease. * @return int|float New stock level. */ - public function update_product_stock( $product_id_with_stock, $stock_quantity = 0, $operation = 'set' ) { + public function update_product_stock( $product_id_with_stock, $stock_quantity = null, $operation = 'set' ) { global $wpdb; // Ensures a row exists to update. @@ -2110,7 +2110,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da if ( 'wc_product_meta_lookup' === $table ) { $price_meta = (array) get_post_meta( $id, '_price', false ); $manage_stock = get_post_meta( $id, '_manage_stock', true ); - $stock = 'yes' === $manage_stock ? wc_stock_amount( get_post_meta( $id, '_stock', true ) ) : 0; + $stock = 'yes' === $manage_stock ? wc_stock_amount( get_post_meta( $id, '_stock', true ) ) : null; $price = wc_format_decimal( get_post_meta( $id, '_price', true ) ); $sale_price = wc_format_decimal( get_post_meta( $id, '_sale_price', true ) ); return array( diff --git a/plugins/woocommerce/includes/interfaces/class-wc-product-data-store-interface.php b/plugins/woocommerce/includes/interfaces/class-wc-product-data-store-interface.php index a4fc9e374b7..4c1a68c94ec 100644 --- a/plugins/woocommerce/includes/interfaces/class-wc-product-data-store-interface.php +++ b/plugins/woocommerce/includes/interfaces/class-wc-product-data-store-interface.php @@ -96,11 +96,11 @@ interface WC_Product_Data_Store_Interface { * * Uses queries rather than update_post_meta so we can do this in one query (to avoid stock issues). * - * @param int $product_id_with_stock Product ID. - * @param int $stock_quantity Stock quantity to update to. - * @param string $operation Either set, increase or decrease. + * @param int $product_id_with_stock Product ID. + * @param int|null $stock_quantity Stock quantity to update to. + * @param string $operation Either set, increase or decrease. */ - public function update_product_stock( $product_id_with_stock, $stock_quantity = 0, $operation = 'set' ); + public function update_product_stock( $product_id_with_stock, $stock_quantity = null, $operation = 'set' ); /** * Update a product's sale count directly. diff --git a/plugins/woocommerce/includes/wc-stock-functions.php b/plugins/woocommerce/includes/wc-stock-functions.php index c023e0e4e9b..4aee1011828 100644 --- a/plugins/woocommerce/includes/wc-stock-functions.php +++ b/plugins/woocommerce/includes/wc-stock-functions.php @@ -21,7 +21,7 @@ defined( 'ABSPATH' ) || exit; * @param int|null $stock_quantity Stock quantity. * @param string $operation Type of operation, allows 'set', 'increase' and 'decrease'. * @param bool $updating If true, the product object won't be saved here as it will be updated later. - * @return bool|int + * @return bool|int|null */ function wc_update_product_stock( $product, $stock_quantity = null, $operation = 'set', $updating = false ) { if ( ! is_a( $product, 'WC_Product' ) ) { diff --git a/plugins/woocommerce/tests/api-core-tests/tests/orders/orders.test.js b/plugins/woocommerce/tests/api-core-tests/tests/orders/orders.test.js index 40c799d24d5..0dacf9751d9 100644 --- a/plugins/woocommerce/tests/api-core-tests/tests/orders/orders.test.js +++ b/plugins/woocommerce/tests/api-core-tests/tests/orders/orders.test.js @@ -282,7 +282,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -355,7 +355,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -434,7 +434,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -510,7 +510,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -575,7 +575,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -648,7 +648,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -721,7 +721,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -786,7 +786,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -863,7 +863,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: 'reduced-rate', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -932,7 +932,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1005,7 +1005,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1070,7 +1070,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1147,7 +1147,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1220,7 +1220,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1312,7 +1312,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1403,7 +1403,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1488,7 +1488,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1574,7 +1574,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1620,7 +1620,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1666,7 +1666,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1712,7 +1712,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1773,7 +1773,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1850,7 +1850,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1891,7 +1891,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1932,7 +1932,7 @@ test.describe.serial( 'Orders API tests', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, diff --git a/plugins/woocommerce/tests/api-core-tests/tests/products/product-list.test.js b/plugins/woocommerce/tests/api-core-tests/tests/products/product-list.test.js index 0bbe5a475e8..b9114779f1a 100644 --- a/plugins/woocommerce/tests/api-core-tests/tests/products/product-list.test.js +++ b/plugins/woocommerce/tests/api-core-tests/tests/products/product-list.test.js @@ -250,7 +250,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -323,7 +323,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -402,7 +402,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -478,7 +478,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -543,7 +543,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -616,7 +616,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -689,7 +689,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -754,7 +754,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -831,7 +831,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: 'reduced-rate', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -900,7 +900,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -973,7 +973,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1038,7 +1038,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1115,7 +1115,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1188,7 +1188,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1280,7 +1280,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1371,7 +1371,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1456,7 +1456,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1542,7 +1542,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1588,7 +1588,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1634,7 +1634,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1680,7 +1680,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1741,7 +1741,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, backorders: 'no', backorders_allowed: false, backordered: false, @@ -1818,7 +1818,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1859,7 +1859,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, @@ -1900,7 +1900,7 @@ test.describe( 'Products API tests: List All Products', () => { tax_status: 'taxable', tax_class: '', manage_stock: false, - stock_quantity: 0, + stock_quantity: null, stock_status: 'instock', backorders: 'no', backorders_allowed: false, diff --git a/plugins/woocommerce/tests/legacy/unit-tests/product/data.php b/plugins/woocommerce/tests/legacy/unit-tests/product/data.php index 965a16ef810..dab7f83d71f 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/product/data.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/product/data.php @@ -135,7 +135,7 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case { $product->set_stock_quantity( 5 ); $product->set_stock_status( 'instock' ); $product->save(); - $this->assertEquals( 0, $product->get_stock_quantity() ); + $this->assertEquals( '', $product->get_stock_quantity() ); $this->assertEquals( 'instock', $product->get_stock_status() ); $product->set_stock_status( 'outofstock' ); $product->save(); diff --git a/plugins/woocommerce/tests/legacy/unit-tests/product/functions.php b/plugins/woocommerce/tests/legacy/unit-tests/product/functions.php index 302c58a448d..be0c50083e5 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/product/functions.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/product/functions.php @@ -917,11 +917,14 @@ class WC_Tests_Product_Functions extends WC_Unit_Test_Case { } /** - * Test: test_wc_update_product_stock_should_return_old_value_if_not_managing_stock. + * Test: test_wc_update_product_stock_should_return_null_if_not_managing_stock. */ - public function test_wc_update_product_stock_should_return_old_value_if_not_managing_stock() { + public function test_wc_update_product_stock_should_return_null_if_not_managing_stock() { $product = WC_Helper_Product::create_simple_product(); - $this->assertEquals( 0, wc_update_product_stock( $product, 3 ) ); + $product->set_stock_quantity( 5 ); + $product->save(); + + $this->assertNull( wc_update_product_stock( $product, 3 ) ); } /** diff --git a/plugins/woocommerce/tests/legacy/unit-tests/product/product-variable.php b/plugins/woocommerce/tests/legacy/unit-tests/product/product-variable.php index 567d8bdc60d..2c2d940b020 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/product/product-variable.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/product/product-variable.php @@ -37,7 +37,7 @@ class WC_Tests_Product_Variable extends WC_Unit_Test_Case { $product->set_stock_quantity( 5 ); $product->set_stock_status( 'instock' ); $product->save(); - $this->assertEquals( 0, $product->get_stock_quantity() ); + $this->assertEquals( '', $product->get_stock_quantity() ); $this->assertEquals( 'outofstock', $product->get_stock_status() ); $product->set_manage_stock( true );