Commit e9d2c7fbcd9 for woocommerce

commit e9d2c7fbcd91b86b448b07b1b4dc911f1381ad86
Author: Ján Mikláš <neosinner@gmail.com>
Date:   Fri Jun 19 14:07:52 2026 +0200

    Fix email preview downloadable file data (#65856)

    * Fix email preview downloadable file data

    * Add changelog entry for email preview downloads

    * Retrigger CI (transient packagist network timeout)

    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

    ---------

    Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/wooplug-6883-email-preview-download-file-object b/plugins/woocommerce/changelog/wooplug-6883-email-preview-download-file-object
new file mode 100644
index 00000000000..83d56eab7ed
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-6883-email-preview-download-file-object
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix email previews for orders with downloadable products.
diff --git a/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php b/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php
index 552b4931928..14cd08352d4 100644
--- a/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php
+++ b/plugins/woocommerce/src/Internal/Admin/EmailPreview/EmailPreview.php
@@ -15,6 +15,7 @@ use WC_Order;
 use WC_Order_Item_Product;
 use WC_Order_Item_Shipping;
 use WC_Product;
+use WC_Product_Download;
 use WC_Product_Variation;
 use WP_User;

@@ -705,14 +706,14 @@ class EmailPreview {
 	/**
 	 * Provide a dummy product file so product->has_file() returns true in preview.
 	 *
-	 * @param array|null $file Current file array or null.
-	 * @return array|null
+	 * @param WC_Product_Download|array|null $file Current file object, array, or null.
+	 * @return WC_Product_Download|array|null
 	 */
 	public function provide_dummy_product_file( $file ) {
 		/**
 		 * Filters whether the current request is an email preview.
 		 *
-		 * When true, provide a dummy product file array so downloadable template parts
+		 * When true, provide a dummy product file so downloadable template parts
 		 * can render during preview.
 		 *
 		 * @since 9.6.0
@@ -720,10 +721,11 @@ class EmailPreview {
 		 * @param bool $is_email_preview Whether preview mode is active.
 		 */
 		if ( apply_filters( 'woocommerce_is_email_preview', false ) ) {
-			return array(
-				'name' => __( 'Sample Download File.pdf', 'woocommerce' ),
-				'file' => 'sample-download.pdf',
-			);
+			$dummy_file = new WC_Product_Download();
+			$dummy_file->set_id( 'preview-dummy' );
+			$dummy_file->set_name( __( 'Sample Download File.pdf', 'woocommerce' ) );
+			$dummy_file->set_file( 'sample-download.pdf' );
+			return $dummy_file;
 		}
 		return $file;
 	}
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 5ff543d7ea8..20abc99d959 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
@@ -8,6 +8,7 @@ use Automattic\WooCommerce\Internal\Admin\EmailPreview\PreviewOrder;
 use WC_Emails;
 use WC_Helper_Order;
 use WC_Product;
+use WC_Product_Download;
 use WC_Unit_Test_Case;

 /**
@@ -237,6 +238,21 @@ class EmailPreviewTest extends WC_Unit_Test_Case {
 		remove_filter( 'woocommerce_prepare_email_for_preview', $email_filter, 10 );
 	}

+	/**
+	 * @testdox Email preview provides dummy product files as download objects.
+	 */
+	public function test_provide_dummy_product_file_returns_download_object_in_preview(): void {
+		add_filter( 'woocommerce_is_email_preview', '__return_true' );
+
+		$file = $this->sut->provide_dummy_product_file( null );
+
+		remove_filter( 'woocommerce_is_email_preview', '__return_true' );
+
+		$this->assertInstanceOf( WC_Product_Download::class, $file );
+		$this->assertSame( 'Sample Download File.pdf', $file->get_name() );
+		$this->assertSame( 'sample-download.pdf', $file->get_file() );
+	}
+
 	/**
 	 * Test that downloadable product appears in email content.
 	 */