Automattic\WooCommerce\Internal\EmailEditor
BlockEmailRenderer::maybe_render_block_email
Maybe render block-based email content.
Method of the class: BlockEmailRenderer{}
No Hooks.
Returns
string|null. Modified email content
Usage
$BlockEmailRenderer = new BlockEmailRenderer(); $BlockEmailRenderer->maybe_render_block_email( $wc_email ): ?string;
- $wc_email(WC_Email) (required)
- WooCommerce email.
BlockEmailRenderer::maybe_render_block_email() BlockEmailRenderer::maybe render block email code WC 11.1.2
public function maybe_render_block_email( \WC_Email $wc_email ): ?string {
$email_post = $this->get_email_post_by_wc_email( $wc_email );
// Without a published post, the file template is the source of truth
// (WP Site Editor pattern). This method runs for every WC_Email when
// the block email feature is enabled, so the fallback is limited to
// emails opted in via the
// `woocommerce_transactional_emails_for_block_editor` filter — for any
// other email the template resolution would silently degrade to the
// generic default block content. Those keep the classic pipeline.
$file_template_content = '';
if ( ! $email_post ) {
if ( ! in_array( $wc_email->id, WCTransactionalEmails::get_transactional_emails(), true ) ) {
return null;
}
// The canonical content (including the `woocommerce_email_content_post_data`
// filter) is used, so what is sent matches both the editor scratchpad
// content and the hash the cleanup migration compared against before
// deleting a post. Keyed by locale as well: plugins may switch it
// per recipient, and the markup contains translated strings.
$cache_key = $wc_email->id . ':' . get_locale();
if ( ! isset( $this->file_template_content_cache[ $cache_key ] ) ) {
$this->file_template_content_cache[ $cache_key ] = WCTransactionalEmailPostsGenerator::compute_canonical_post_content( $wc_email );
}
$file_template_content = $this->file_template_content_cache[ $cache_key ];
if ( '' === $file_template_content ) {
return null;
}
}
$woo_content = $this->woo_content_processor->get_woo_content( $wc_email );
return $this->render_block_email( $email_post, $file_template_content, $woo_content, $wc_email );
}