Automattic\WooCommerce\Internal\EmailEditor

Integration::update_email_preview_data │ private │ WC 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.

Метод класса: Integration{}

Хуков нет.

Возвращает

string. The updated preview data with placeholders replaced.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->update_email_preview_data( $data, $email_type, $post_id );
$data(строка) (обязательный)
The preview data.
$email_type(строка) (обязательный)
The email type identifier (e.g., 'customer_processing_order').
$post_id(int)
The post ID.

Код Integration::update_email_preview_data() WC 11.3.0

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

	if ( ! empty( $post_id ) ) {
		$type_param = WCTransactionalEmailPostsManager::get_instance()->get_email_type_class_name_from_post_id( $post_id );
	} elseif ( ! empty( $email_type ) ) {
		$type_param = WCTransactionalEmailPostsManager::get_instance()->get_email_type_class_name_from_email_id( $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 );
}