Automattic\WooCommerce\Internal\Admin\EmailPreview

EmailPreview::provide_dummy_product_file │ public │ WC 1.0

Provide a dummy product file so product->has_file() returns true in preview.

Method of the class: EmailPreview{}

Hooks from the method

Returns

WC_Product_Download|array|null.

Usage

$EmailPreview = new EmailPreview();
$EmailPreview->provide_dummy_product_file( $file );
$file(WC_Product_Download|array|null) (required)
Current file object, array, or null.

EmailPreview::provide_dummy_product_file() code WC 11.1.2

public function provide_dummy_product_file( $file ) {
	/**
	 * Filters whether the current request is an email preview.
	 *
	 * When true, provide a dummy product file so downloadable template parts
	 * can render during preview.
	 *
	 * @since 9.6.0
	 *
	 * @param bool $is_email_preview Whether preview mode is active.
	 */
	if ( apply_filters( 'woocommerce_is_email_preview', false ) ) {
		$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;
}