Commit 6540f7caaa for woocommerce
commit 6540f7caaa82b1efc113e05ce52f09ff555ab7b9
Author: Jason Kytros <jason.kytros@automattic.com>
Date: Fri May 23 14:21:18 2025 +0300
[Product Importer]: Allow empty Download Limit/Expiry values (#58150)
* [Product Importer]: Allow empty Download Limit/Expiry values
* Add changefile(s) from automation for the following project(s): woocommerce
* Updated unit tests
* Review
---------
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Naman Malhotra <naman03malhotra@gmail.com>
diff --git a/plugins/woocommerce/changelog/58150-fix-wooplug-1009 b/plugins/woocommerce/changelog/58150-fix-wooplug-1009
new file mode 100644
index 0000000000..82abbd9cb8
--- /dev/null
+++ b/plugins/woocommerce/changelog/58150-fix-wooplug-1009
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fixed an issue that prevented the Download Limit and Expiry fields from being cleared during product import.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php b/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php
index c0658aa3c9..8a48b7a19a 100644
--- a/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php
+++ b/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php
@@ -3,7 +3,7 @@
* WooCommerce Product CSV importer
*
* @package WooCommerce\Import
- * @version 3.1.0
+ * @version 10.0.0
*/
use Automattic\WooCommerce\Enums\ProductStatus;
@@ -693,9 +693,15 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
*
* @param int $value field value.
*
- * @return int
+ * @return int|string
*/
public function parse_int_field( $value ) {
+ // Similar to WC_Meta_Box_Product_Data::save, do not cast the empty value to int.
+ // An empty value indicates that the field should be cleared.
+ if ( '' === $value ) {
+ return $value;
+ }
+
// Remove the ' prepended to fields that start with - if needed.
$value = $this->unescape_data( $value );
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/importer/product.php b/plugins/woocommerce/tests/legacy/unit-tests/importer/product.php
index 5cde7b37ff..4a4f547d93 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/importer/product.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/importer/product.php
@@ -363,8 +363,8 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
'sale_price' => '18',
'regular_price' => '20',
'shipping_class_id' => 0,
- 'download_limit' => 0,
- 'download_expiry' => 0,
+ 'download_limit' => '',
+ 'download_expiry' => '',
'product_url' => '',
'button_text' => '',
'status' => ProductStatus::PUBLISH,
@@ -460,8 +460,8 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
'sale_price' => '180',
'regular_price' => '199',
'shipping_class_id' => 0,
- 'download_limit' => 0,
- 'download_expiry' => 0,
+ 'download_limit' => '',
+ 'download_expiry' => '',
'product_url' => 'https://woocommerce.com/products/product-csv-import-suite/',
'button_text' => 'Buy on WooCommerce.com',
'status' => ProductStatus::PUBLISH,
@@ -496,8 +496,8 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
'sale_price' => '',
'regular_price' => '',
'shipping_class_id' => 0,
- 'download_limit' => 0,
- 'download_expiry' => 0,
+ 'download_limit' => '',
+ 'download_expiry' => '',
'product_url' => '',
'button_text' => '',
'status' => ProductStatus::PUBLISH,
@@ -548,8 +548,8 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
'sale_price' => '',
'regular_price' => '20',
'shipping_class_id' => 0,
- 'download_limit' => 0,
- 'download_expiry' => 0,
+ 'download_limit' => '',
+ 'download_expiry' => '',
'product_url' => '',
'button_text' => '',
'status' => ProductStatus::PUBLISH,
@@ -593,8 +593,8 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
'sale_price' => '17.99',
'regular_price' => '20',
'shipping_class_id' => 0,
- 'download_limit' => 0,
- 'download_expiry' => 0,
+ 'download_limit' => '',
+ 'download_expiry' => '',
'product_url' => '',
'button_text' => '',
'status' => ProductStatus::PUBLISH,
@@ -638,8 +638,8 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
'sale_price' => '',
'regular_price' => '',
'shipping_class_id' => 0,
- 'download_limit' => 0,
- 'download_expiry' => 0,
+ 'download_limit' => '',
+ 'download_expiry' => '',
'product_url' => '',
'button_text' => '',
'status' => ProductStatus::PUBLISH,