Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCTransactionalEmailPostsGenerator::get_email_templatepublicWC 1.0

Get the email template for the given email.

Looks for the initial email block content in plugins/woocommerce/templates/emails/block.

Method of the class: WCTransactionalEmailPostsGenerator{}

No Hooks.

Returns

String. The email template.

Usage

$WCTransactionalEmailPostsGenerator = new WCTransactionalEmailPostsGenerator();
$WCTransactionalEmailPostsGenerator->get_email_template( $email );
$email(WC_Email) (required)
The email object.

WCTransactionalEmailPostsGenerator::get_email_template() code WC 10.3.6

public function get_email_template( $email ) {
	$template_name = str_replace( 'plain', 'block', $email->template_plain );

	try {
		$template_html = wc_get_template_html(
			$template_name,
			array()
		);
	} catch ( \Exception $e ) {
		$template_html = '';
	}

	// wc_get_template_html does not throw an error when the template is not found.
	// We need to check if the template is not found by checking the template_html content.
	$has_template_error =
		StringUtil::contains( $template_html, 'No such file or directory', false ) ||
		StringUtil::contains( $template_html, 'Failed to open stream', false ) ||
		StringUtil::contains( $template_html, 'Warning: include', false );

	if ( is_wp_error( $template_html ) || empty( $template_html ) || $has_template_error ) {
		$default_template_name = 'emails/block/default-block-content.php';
		$template_html         = wc_get_template_html(
			$default_template_name,
			array()
		);
	}

	return $template_html;
}