Automattic\WooCommerce\Internal\Orders
OrderActionsRestController::get_email_template_by_id
Retrieve an email template class using its ID, if it is available.
Method of the class: OrderActionsRestController{}
No Hooks.
Returns
WC_Email|null. The email template class if it is available, otherwise null.
Usage
// private - for code of main (parent) class only $result = $this->get_email_template_by_id( $template_id, ?array $available_templates ): ?WC_Email;
- $template_id(string) (required)
- The ID of the desired email template class.
- ?array $available_templates
- .
Default:null
OrderActionsRestController::get_email_template_by_id() OrderActionsRestController::get email template by id code WC 10.6.2
private function get_email_template_by_id( string $template_id, ?array $available_templates = null ): ?WC_Email {
if ( is_null( $available_templates ) ) {
$available_templates = WC()->mailer()->emails;
}
$matching_templates = array_filter(
$available_templates,
fn( $template ) => $template->id === $template_id
);
if ( empty( $matching_templates ) ) {
return null;
}
return reset( $matching_templates );
}