Automattic\WooCommerce\Internal\EmailEditor
Integration::get_preview_subject_for_email_type
Build the preview subject for an email type, mirroring the post-based preview subject (placeholders resolved against the preview order).
Method of the class: Integration{}
No Hooks.
Returns
string. The preview subject.
Usage
// private - for code of main (parent) class only $result = $this->get_preview_subject_for_email_type( $email_type, $email ): string;
- $email_type(string) (required)
- The email type identifier.
- $email(WC_Email) (required)
- The email instance, used for fallbacks.
Integration::get_preview_subject_for_email_type() Integration::get preview subject for email type code WC 11.1.2
private function get_preview_subject_for_email_type( string $email_type, \WC_Email $email ): string {
$class_name = WCTransactionalEmailPostsManager::get_instance()->get_email_type_class_name_from_email_id( $email_type );
if ( ! empty( $class_name ) ) {
try {
$email_preview = wc_get_container()->get( EmailPreview::class );
$email_preview->set_email_type( $class_name );
return $email_preview->get_subject();
} catch ( \Throwable $e ) {
// Fall through to the WC_Email fallbacks below.
unset( $e );
}
}
// Third-party get_subject() implementations may assume send-time state
// (e.g. Bookings dereferences its booking object), so it must only run
// guarded; the title is the always-safe last resort.
try {
return (string) $email->get_subject();
} catch ( \Throwable $e ) {
return (string) $email->get_title();
}
}