Commit bdf349fdb23 for woocommerce
commit bdf349fdb2386215c6b2302845d685bb4036917e
Author: Yuliyan Slavchev <yuliyan.slavchev@gmail.com>
Date: Fri Jun 19 16:14:51 2026 +0300
Ensure email previews return only the dummy downloadable item (#65865)
diff --git a/plugins/woocommerce/changelog/fix-email-preview-downloadable-items b/plugins/woocommerce/changelog/fix-email-preview-downloadable-items
new file mode 100644
index 00000000000..37117b991ef
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-email-preview-downloadable-items
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent email previews from showing unrelated dummy products as downloadable items.
diff --git a/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php b/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php
index 14cd08352d4..be2461779a0 100644
--- a/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php
+++ b/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php
@@ -634,7 +634,7 @@ class EmailPreview {
add_filter( 'woocommerce_is_downloadable', array( $this, 'force_product_downloadable' ), 10, 1 );
add_filter( 'woocommerce_product_file', array( $this, 'provide_dummy_product_file' ), 10, 1 );
// Provide dummy downloadable items for email preview.
- add_filter( 'woocommerce_order_get_downloadable_items', array( $this, 'get_dummy_downloadable_items' ), 10, 1 );
+ add_filter( 'woocommerce_order_get_downloadable_items', array( $this, 'get_dummy_downloadable_items' ) );
}
/**
@@ -733,10 +733,9 @@ class EmailPreview {
/**
* Get dummy downloadable items for email preview.
*
- * @param array $downloads Existing downloads.
* @return array
*/
- public function get_dummy_downloadable_items( $downloads ) {
+ public function get_dummy_downloadable_items() {
$dummy_downloads = array(
array(
'product_name' => $this->get_dummy_downloadable_product()->get_name(),
@@ -747,7 +746,7 @@ class EmailPreview {
),
);
- return array_merge( $downloads, $dummy_downloads );
+ return $dummy_downloads;
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
index 20abc99d959..38e059f89bc 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
@@ -253,6 +253,39 @@ class EmailPreviewTest extends WC_Unit_Test_Case {
$this->assertSame( 'sample-download.pdf', $file->get_file() );
}
+ /**
+ * @testdox Email preview downloadable items ignore downloads resolved from the dummy order.
+ */
+ public function test_get_dummy_downloadable_items_returns_only_preview_downloads(): void {
+ $downloads = array(
+ array(
+ 'product_name' => 'Unexpected Dummy Product',
+ 'product_id' => 0,
+ 'download_url' => 'https://example.com/unexpected',
+ 'download_name' => 'Unexpected Download.pdf',
+ 'access_expires' => time() + DAY_IN_SECONDS,
+ ),
+ );
+
+ try {
+ $this->sut->set_up_filters();
+ /**
+ * Filters the list of downloadable items for an order.
+ *
+ * @since 3.2.0
+ *
+ * @param array $downloads Downloadable items.
+ * @param WC_Order $order Order object.
+ */
+ $result = apply_filters( 'woocommerce_order_get_downloadable_items', $downloads, new PreviewOrder() );
+ } finally {
+ $this->sut->clean_up_filters();
+ }
+
+ $this->assertCount( 1, $result, 'Existing downloads from dummy order permission records must not be merged into preview output.' );
+ $this->assertSame( 'Sample Download File.pdf', $result[0]['download_name'], 'Preview output should keep the synthetic downloadable item.' );
+ }
+
/**
* Test that downloadable product appears in email content.
*/