woocommerce_coupon_code_block_auto_generate filter-hookWC 10.6.0

Filters the auto-generated coupon code for the coupon-code block.

Integrators (MailPoet, WooCommerce, third-party plugins) hook into this filter to generate a WooCommerce coupon at send time and return its code.

Usage

add_filter( 'woocommerce_coupon_code_block_auto_generate', 'wp_kama_woocommerce_coupon_code_block_auto_generate_filter', 10, 3 );

/**
 * Function for `woocommerce_coupon_code_block_auto_generate` filter-hook.
 * 
 * @param string            $coupon_code       The coupon code. Empty by default.
 * @param array             $attrs             Block attributes (discountType, amount, expiryDay, etc.).
 * @param Rendering_Context $rendering_context The rendering context with email-specific data (recipient email, user ID, etc.).
 *
 * @return string
 */
function wp_kama_woocommerce_coupon_code_block_auto_generate_filter( $coupon_code, $attrs, $rendering_context ){

	// filter...
	return $coupon_code;
}
$coupon_code(string)
The coupon code. Empty by default.
$attrs(array)
Block attributes (discountType, amount, expiryDay, etc.).
$rendering_context(Rendering_Context)
The rendering context with email-specific data (recipient email, user ID, etc.).

Changelog

Since 10.6.0 Introduced.

Where the hook is called

Coupon_Code::render_content()
woocommerce_coupon_code_block_auto_generate
woocommerce/packages/email-editor/src/Integrations/WooCommerce/Renderer/Blocks/class-coupon-code.php 54-59
$coupon_code = apply_filters(
	'woocommerce_coupon_code_block_auto_generate',
	'',
	$attrs,
	$rendering_context
);

Where the hook is used in WooCommerce

woocommerce/packages/email-editor/src/Integrations/WooCommerce/class-coupon-code-generator.php 35
add_filter( 'woocommerce_coupon_code_block_auto_generate', array( $this, 'generate_coupon' ), 10, 3 );