WooCommerce Code Reference

Coupon_Code extends Abstract_Block_Renderer
in package

Renders the woocommerce/coupon-code block for email.

For "existing" source, the block content passes through unchanged. For "createNew" source, the placeholder (XXXX-XXXXXX-XXXX) is replaced with a generated coupon code via the woocommerce_coupon_code_block_auto_generate filter.

Table of Contents

COUPON_CODE_PLACEHOLDER  = 'XXXX-XXXXXX-XXXX'
render()  : string
Render the block.
add_spacer()  : string
Add a spacer around the block for vertical spacing (margin-top).
compile_css()  : string
Compile objects containing CSS properties to a string.
get_inner_content()  : string
Extract inner content from a wrapper element.
get_styles_from_block()  : array<string|int, mixed>
Wrapper for wp_style_engine_get_styles which ensures all values are returned.
render_content()  : string
Render the coupon code block content for email.

Constants

Methods

add_spacer()

Add a spacer around the block for vertical spacing (margin-top).

protected add_spacer(string $content, array<string|int, mixed> $email_attrs) : string

Horizontal root padding is applied uniformly by Content_Renderer::render_block() so that all blocks — including those using render_email_callback without Abstract_Block_Renderer — receive consistent padding.

Parameters
$content : string

The block content.

$email_attrs : array<string|int, mixed>

The email attributes.

Return values
string

get_inner_content()

Extract inner content from a wrapper element.

protected get_inner_content(string $block_content[, string $tag_name = 'div' ]) : string

Removes the outer wrapper element (e.g., div) and returns only the inner HTML content. This is useful when you need to strip the wrapper and use only the inner content.

Parameters
$block_content : string

Block content with wrapper element.

$tag_name : string = 'div'

Tag name of the wrapper element (default: 'div').

Return values
stringInner content without the wrapper element, or original content if wrapper not found.

get_styles_from_block()

Wrapper for wp_style_engine_get_styles which ensures all values are returned.

protected get_styles_from_block(array<string|int, mixed> $block_styles[, bool $skip_convert_vars = false ]) : array<string|int, mixed>
Parameters
$block_styles : array<string|int, mixed>

Array of block styles.

$skip_convert_vars : bool = false

If true, --wp_preset--spacing--x type values will be left in the original var:preset:spacing:x format.

Return values
array<string|int, mixed>

render_content()

Render the coupon code block content for email.

protected render_content(string $block_content, array<string|int, mixed> $parsed_block, Rendering_Context $rendering_context) : string
Parameters
$block_content : string

Block content from the standard WP render.

$parsed_block : array<string|int, mixed>

Parsed block data.

$rendering_context : Rendering_Context

Rendering context with email-specific data.

Return values
string