woocommerce_email_editor_rendering_email_context │ хук-фильтр │ WC 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().

Использование

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(массив)

Email-specific context data.

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

  • recipient_email(строка)
    The recipient's email address.

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

  • email_type(строка)
    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.

Список изменений

С версии 1.9.0 Введена.

Где вызывается хук

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

Где используется хук в 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 136
add_filter( 'woocommerce_email_editor_rendering_email_context', $filter_callback, 10, 1 );
woocommerce/src/Internal/EmailEditor/BlockEmailRenderer.php 151
remove_filter( 'woocommerce_email_editor_rendering_email_context', $filter_callback );
woocommerce/src/Internal/EmailEditor/BlockEmailRenderer.php 163
remove_filter( 'woocommerce_email_editor_rendering_email_context', $filter_callback );
woocommerce/src/Internal/EmailEditor/Integration.php 560
add_filter( 'woocommerce_email_editor_rendering_email_context', array( $send_preview, 'add_preview_context' ) );
woocommerce/src/Internal/EmailEditor/Integration.php 570
remove_filter( 'woocommerce_email_editor_rendering_email_context', array( $send_preview, 'add_preview_context' ) );