woocommerce_email_editor_rendering_email_context
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', 10, 3 );
/**
* Function for `woocommerce_email_editor_rendering_email_context` filter-hook.
*
* @param array $email_context Email-specific context data.
* @param WP_Post|null $post Email post being rendered.
* @param WP_Block_Template|null $template Block template being rendered.
*
* @return array
*/
function wp_kama_woocommerce_email_editor_rendering_context_filter( $email_context, $post, $template ){
// 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. - is_rtl(true|false)
Optional. Whether this email render should use RTL direction.
-
- $post(WP_Post|null)
- Email post being rendered.
- $template(WP_Block_Template|null)
- Block template being rendered.
Changelog
| Since 1.9.0 | Introduced. |
Where the hook is called
woocommerce_email_editor_rendering_email_context
woocommerce/packages/email-editor/src/Engine/Renderer/ContentRenderer/class-content-renderer.php 596
$email_context = apply_filters( 'woocommerce_email_editor_rendering_email_context', array(), $post, $template );
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 );