Commit 4c55ae11371 for woocommerce
commit 4c55ae1137189701ed90fc735ddae52957e2e3e8
Author: Chris Lilitsas <1105590+xristos3490@users.noreply.github.com>
Date: Thu Jul 2 18:54:15 2026 +0300
Fix: Preserve pending review status on product CSV export/import (#66194)
* fix: preserve pending review status on product CSV export/import
* fix: address review feedback on published field annotation and test cleanup
diff --git a/plugins/woocommerce/changelog/28798-fix-import-pending-review-products b/plugins/woocommerce/changelog/28798-fix-import-pending-review-products
new file mode 100644
index 00000000000..901580a9c4f
--- /dev/null
+++ b/plugins/woocommerce/changelog/28798-fix-import-pending-review-products
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Preserve the "Pending review" product status when exporting and re-importing products via CSV, instead of importing them as drafts.
diff --git a/plugins/woocommerce/includes/export/class-wc-product-csv-exporter.php b/plugins/woocommerce/includes/export/class-wc-product-csv-exporter.php
index 329f617b46b..1cceaf2ca53 100644
--- a/plugins/woocommerce/includes/export/class-wc-product-csv-exporter.php
+++ b/plugins/woocommerce/includes/export/class-wc-product-csv-exporter.php
@@ -332,6 +332,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
ProductStatus::DRAFT => -1,
ProductStatus::PRIVATE => 0,
ProductStatus::PUBLISH => 1,
+ ProductStatus::PENDING => 2,
);
// Fix display for variations when parent product is a draft.
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 8a48b7a19ac..0c635e874f9 100644
--- a/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php
+++ b/plugins/woocommerce/includes/import/class-wc-product-csv-importer.php
@@ -725,12 +725,12 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
}
/**
- * Parse the published field. 1 is published, 0 is private, -1 is draft.
+ * Parse the published field. 1 is published, 0 is private, -1 is draft, 2 is pending review.
* Alternatively, 'true' can be used for published and 'false' for draft.
*
* @param string $value Field value.
*
- * @return float|string
+ * @return int|float|string
*/
public function parse_published_field( $value ) {
if ( '' === $value ) {
@@ -913,6 +913,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
-1 => ProductStatus::DRAFT,
0 => ProductStatus::PRIVATE,
1 => ProductStatus::PUBLISH,
+ 2 => ProductStatus::PENDING,
);
$data['status'] = $statuses[ $published ] ?? ProductStatus::DRAFT;
diff --git a/plugins/woocommerce/tests/php/includes/exporter/class-wc-product-csv-exporter-test.php b/plugins/woocommerce/tests/php/includes/exporter/class-wc-product-csv-exporter-test.php
index beef95c5c06..7d9e5bc4aeb 100644
--- a/plugins/woocommerce/tests/php/includes/exporter/class-wc-product-csv-exporter-test.php
+++ b/plugins/woocommerce/tests/php/includes/exporter/class-wc-product-csv-exporter-test.php
@@ -68,4 +68,34 @@ class WC_Product_CSV_Exporter_Test extends \WC_Unit_Test_Case {
}
remove_filter( 'woocommerce_product_export_product_query_args', array( $this, 'set_export_product_query_args' ) );
}
+
+ /**
+ * @testdox pending review products should export with a distinct published value.
+ */
+ public function test_get_column_value_published_for_pending_product() {
+ $product = new WC_Product_Simple();
+ $product->set_status( ProductStatus::PENDING );
+ $product->save();
+
+ $reflected_exporter = new ReflectionClass( WC_Product_CSV_Exporter::class );
+ $get_data_to_export = $reflected_exporter->getMethod( 'get_data_to_export' );
+ $get_data_to_export->setAccessible( true );
+
+ $this->product_ids = array( $product->get_id() );
+
+ add_filter( 'woocommerce_product_export_product_query_args', array( $this, 'set_export_product_query_args' ) );
+
+ try {
+ $exporter = new WC_Product_CSV_Exporter();
+ $exporter->prepare_data_to_export();
+ $data = $get_data_to_export->invoke( $exporter );
+
+ $this->assertNotEmpty( $data, 'Pending review product should be included in the export.' );
+ foreach ( $data as $row ) {
+ $this->assertEquals( 2, $row['published'], 'Pending review products should not export as draft (-1).' );
+ }
+ } finally {
+ remove_filter( 'woocommerce_product_export_product_query_args', array( $this, 'set_export_product_query_args' ) );
+ }
+ }
}
diff --git a/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php b/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php
index bde2455c832..379e14643ef 100644
--- a/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php
+++ b/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php
@@ -64,6 +64,28 @@ class WC_Product_CSV_Importer_Test extends \WC_Unit_Test_Case {
$this->assertEquals( ProductStatus::PUBLISH, $variation['status'] );
}
+ /**
+ * @testdox published value of 2 maps to the pending review status on import.
+ */
+ public function test_expand_data_maps_published_to_pending() {
+ $csv_file = __DIR__ . '/sample.csv';
+
+ $reflected_importer = new ReflectionClass( WC_Product_CSV_Importer::class );
+ $expand_data = $reflected_importer->getMethod( 'expand_data' );
+ $expand_data->setAccessible( true );
+
+ $importer = new WC_Product_CSV_Importer( $csv_file );
+ $parsed = $expand_data->invoke(
+ $importer,
+ array(
+ 'type' => array( ProductType::SIMPLE ),
+ 'published' => 2,
+ )
+ );
+
+ $this->assertEquals( ProductStatus::PENDING, $parsed['status'] );
+ }
+
/**
* @testdox Test that the importer calculates the percent complete as 99 when it's >= 99.5% through the file.
*/