From 0f54e570936b97df72fe50a4fd33fb3f0a579e37 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 11 Aug 2017 11:07:12 +0100 Subject: [PATCH] CSV Import; correctly set stock props. Closes #16398 --- .../import/class-wc-product-csv-importer.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index a8170a5f333..cdc6cd82cec 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -283,6 +283,20 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { return floatval( $value ); } + /** + * Parse the stock qty field. + * + * @param string $value Field value. + * @return float|string + */ + public function parse_stock_quantity_field( $value ) { + if ( '' === $value ) { + return $value; + } + + return wc_stock_amount( $value ); + } + /** * Parse a category field from a CSV. * Categories are separated by commas and subcategories are "parent > subcategory". @@ -488,7 +502,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { 'purchase_note' => 'wp_filter_post_kses', 'price' => 'wc_format_decimal', 'regular_price' => 'wc_format_decimal', - 'stock_quantity' => 'wc_stock_amount', + 'stock_quantity' => array( $this, 'parse_stock_quantity_field' ), 'category_ids' => array( $this, 'parse_categories_field' ), 'tag_ids' => array( $this, 'parse_tags_field' ), 'shipping_class_id' => array( $this, 'parse_shipping_class_field' ), @@ -584,7 +598,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { } if ( isset( $data['stock_quantity'] ) ) { - $data['manage_stock'] = 0 < $data['stock_quantity']; + if ( '' === $data['stock_quantity'] ) { + $data['manage_stock'] = false; + $data['stock_status'] = isset( $data['stock_status'] ) ? $data['stock_status'] : true; + } else { + $data['manage_stock'] = true; + $data['stock_status'] = 0 < $data['stock_quantity']; + } } // Stock is bool.