woocommerce_email_editor_rendering_email_context filter-hookWC 1.9.0

Filter the email-specific context data passed to block renderers.

This allows email sending systems to provide context data such as user ID, email address, order information, etc., that can be used by blocks during rendering.

Blocks that need cart product information can derive it from the user_id or recipient_email using CartCheckoutUtils::get_cart_product_ids_for_user().

Usage

add_filter( 'woocommerce_email_editor_rendering_email_context', 'wp_kama_woocommerce_email_editor_rendering_context_filter' );

/**
 * Function for `woocommerce_email_editor_rendering_email_context` filter-hook.
 * 
 * @param array $email_context Email-specific context data.
 *
 * @return array
 */
function wp_kama_woocommerce_email_editor_rendering_context_filter( $email_context ){

	// filter...
	return $email_context;
}
$email_context(array)

Email-specific context data.

  • user_id(int)
    The ID of the user receiving the email.

  • recipient_email(string)
    The recipient's email address.

  • order_id(int)
    The order ID (for order-related emails).

  • email_type(string)
    The type of email being rendered.

Changelog

Since 1.9.0 Introduced.

Where the hook is called

Content_Renderer::render_block()
woocommerce_email_editor_rendering_email_context
woocommerce/packages/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php 213
$email_context = apply_filters( 'woocommerce_email_editor_rendering_email_context', array() );

Where the hook is used in WooCommerce

woocommerce/packages/email-editor/src/Engine/class-send-preview-email.php 100
remove_filter( 'woocommerce_email_editor_rendering_email_context', array( $this, 'add_preview_context' ) );
woocommerce/packages/email-editor/src/Engine/class-send-preview-email.php 90
add_filter( 'woocommerce_email_editor_rendering_email_context', array( $this, 'add_preview_context' ) );
woocommerce/src/Internal/EmailEditor/BlockEmailRenderer.php 106
remove_filter( 'woocommerce_email_editor_rendering_email_context', $filter_callback );
woocommerce/src/Internal/EmailEditor/BlockEmailRenderer.php 114
remove_filter( 'woocommerce_email_editor_rendering_email_context', $filter_callback );
woocommerce/src/Internal/EmailEditor/BlockEmailRenderer.php 97
add_filter( 'woocommerce_email_editor_rendering_email_context', $filter_callback, 10, 1 );