__( 'HTML template', 'woocommerce' ),
'template_plain' => __( 'Plain text template', 'woocommerce' ),
);
foreach ( $templates as $template_type => $title ) :
$template = $this->get_template( $template_type );
if ( empty( $template ) ) {
continue;
}
$local_file = $this->get_theme_template_file( $template );
$core_file = $this->template_base . $template;
$template_file = apply_filters( 'woocommerce_locate_core_template', $core_file, $template, $this->template_base, $this->id );
$template_dir = apply_filters( 'woocommerce_template_directory', 'woocommerce', $template );
?>
' . esc_html( trailingslashit( basename( get_stylesheet_directory() ) ) . $template_dir . '/' . $template ) . '' );
?>
' . esc_html( plugin_basename( $template_file ) ) . '', '' . esc_html( trailingslashit( basename( get_stylesheet_directory() ) ) . $template_dir . '/' . $template ) . '' );
?>
AltBody = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
}
}
/**
* Get an option or transient for email preview.
*
* @param string $key Option key.
* @param mixed $empty_value Value to use when option is empty.
*/
protected function get_option_or_transient( string $key, $empty_value = null ) {
$option = $this->get_option( $key, $empty_value );
/**
* This filter is documented in templates/emails/email-styles.php
*
* @since 9.6.0
* @param bool $is_email_preview Whether the email is being previewed.
*/
$is_email_preview = apply_filters( 'woocommerce_is_email_preview', false );
if ( $is_email_preview ) {
$plugin_id = $this->plugin_id;
$email_id = $this->id;
$transient = get_transient( "{$plugin_id}{$email_id}_{$key}" );
if ( false !== $transient ) {
$option = $transient ? $transient : $empty_value;
}
}
return $option;
}
/**
* Gerenerates the HTML content for the email from a block based email.
* and if so, it renders the block email content.
*
* @return string|null
*/
private function get_block_email_html_content(): ?string {
if ( ! $this->block_email_editor_enabled ) {
return null;
}
/** Service for rendering emails from block content @var BlockEmailRenderer $renderer */
$renderer = wc_get_container()->get( BlockEmailRenderer::class );
return $renderer->maybe_render_block_email( $this );
}
/**
* Prevent lazy loading on attachment images in email context by adding skip classes.
* This is hooked into the wp_get_attachment_image_attributes filter.
*
* @param array $attributes The image attributes array.
* @return array The modified image attributes array.
*/
public function prevent_lazy_loading_on_attachment( $attributes ) {
// Only process if we're currently sending an email.
if ( ! $this->sending ) {
return $attributes;
}
// Skip classes to prevent lazy loading plugins from applying lazy loading.
// These are the most common skip classes used by popular lazy loading plugins.
$skip_classes = array( 'skip-lazy', 'no-lazyload', 'lazyload-disabled', 'no-lazy', 'skip-lazyload' );
// Add skip classes to prevent lazy loading plugins from applying lazy loading.
if ( isset( $attributes['class'] ) ) {
$classes = array_filter( array_map( 'trim', explode( ' ', $attributes['class'] ) ) );
$classes = array_unique( array_merge( $classes, $skip_classes ) );
$attributes['class'] = implode( ' ', $classes );
} else {
// No class attribute exists, add one with skip classes.
$attributes['class'] = implode( ' ', $skip_classes );
}
// Add data-skip-lazy attribute as an additional safeguard.
$attributes['data-skip-lazy'] = 'true';
return $attributes;
}
}