Automattic\WooCommerce\Internal\EmailEditor

Integration::update_email_preview_dataprivateWC 1.0

Filter email preview data to replace placeholders with actual content.

This method retrieves the appropriate email type based on the request, generates the email content using the WooContentProcessor, and replaces the placeholder in the preview HTML.

Method of the class: Integration{}

No Hooks.

Returns

String. The updated preview data with placeholders replaced.

Usage

// private - for code of main (parent) class only
$result = $this->update_email_preview_data( $data, $email_type );
$data(string) (required)
The preview data.
$email_type(string) (required)
The email type identifier (e.g., 'customer_processing_order').

Integration::update_email_preview_data() code WC 10.3.6

private function update_email_preview_data( $data, string $email_type ) {
	$type_param = EmailPreview::DEFAULT_EMAIL_TYPE;

	if ( ! empty( $email_type ) ) {
		$type_param = WCTransactionalEmailPostsManager::get_instance()->get_email_type_class_name_from_template_name( $email_type );
	}

	$email_preview = wc_get_container()->get( EmailPreview::class );

	try {
		$message = $email_preview->generate_placeholder_content( $type_param );
	} catch ( \InvalidArgumentException $e ) {
		// If the provided type was invalid, fall back to the default.
		try {
			$message = $email_preview->generate_placeholder_content( EmailPreview::DEFAULT_EMAIL_TYPE );
		} catch ( \Throwable $e ) {
			return $data;
		}
	} catch ( \Throwable $e ) {
		return $data;
	}

	return str_replace( BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER, $message, $data );
}