Automattic\WooCommerce\Internal\EmailEditor

WooContentProcessor::prepare_css │ public │ WC 10.8.0

Filter CSS for the email. The CSS from the email editor was already inlined. The method hooks to woocommerce_email_styles and removes CSS rules that we don't want to apply to the email.

Typography properties (font-size, font-weight, line-height, letter-spacing) are stripped because the email editor theme controls all typography via theme.json. Leaving these in the WooCommerce CSS would override the editor's heading sizes and weights.

Text alignment is stripped from the plain heading rules so headings keep the alignment set in the editor instead of being forced to the left.

Method of the class: WooContentProcessor{}

No Hooks.

Returns

string.

Usage

$WooContentProcessor = new WooContentProcessor();
$WooContentProcessor->prepare_css( $css ): string;
$css(string) (required)
CSS.

Changelog

Since 10.8.0 Introduced.

WooContentProcessor::prepare_css() code WC 11.3.0

public function prepare_css( string $css ): string {
	remove_filter( 'woocommerce_email_styles', array( $this, 'prepare_css' ) );

	// Remove text-align from the plain h1-h6 rules. They force headings to the left (right in RTL),
	// which overrides the alignment set in the editor.
	$css = (string) preg_replace_callback(
		'/(^|[{}])(\s*h[1-6]\s*\{)([^}]*)/',
		fn( array $matches ): string => $matches[1] . $matches[2] . preg_replace( '/text-align\s*:\s*[^;]+;/', '', $matches[3] ),
		$css
	);

	// Remove typography declarations from WooCommerce CSS.
	// The email editor theme.json controls all typography; WC CSS would override it.
	return (string) preg_replace(
		array(
			'/color\s*:\s*[^;]+;/',
			'/font-family\s*:\s*[^;]+;/',
			'/font-size\s*:\s*[^;]+;/',
			'/font-weight\s*:\s*[^;]+;/',
			'/line-height\s*:\s*[^;]+;/',
			'/letter-spacing\s*:\s*[^;]+;/',
		),
		'',
		$css
	);
}