Automattic\WooCommerce\Internal\EmailEditor\EmailTemplates

TemplatesController::filter_email_templatespublicWC 1.0

Filters out email templates from the block templates list in the Site Editor.

This function is necessary to prevent email templates from appearing in the Site Editor's template list. Email templates are stored in the database with the same post type as site templates, which causes them to be included in the Site Editor by default. By filtering them out, we ensure that only relevant site templates are displayed, improving the user experience and maintaining the intended separation between email and site templates.

Method of the class: TemplatesController{}

No Hooks.

Returns

Array. The filtered list of block templates.

Usage

$TemplatesController = new TemplatesController();
$TemplatesController->filter_email_templates( $templates );
$templates(array) (required)
The list of block templates.

TemplatesController::filter_email_templates() code WC 10.3.6

public function filter_email_templates( $templates ) {
	// Skip filtering if we're in a REST API request to avoid affecting API endpoints.
	if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
		return $templates;
	}

	if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) {
		return $templates;
	}

	$current_screen = get_current_screen();
	if ( $current_screen && 'site-editor' === $current_screen->id ) {
		$templates = array_filter(
			$templates,
			function ( $template ) {
				return WooEmailTemplate::TEMPLATE_SLUG !== $template->slug;
			}
		);
	}

	return $templates;
}