Automattic\WooCommerce\Blocks\BlockTypes

CouponCode::renderprotectedWC 1.0

Render the coupon code block.

Method of the class: CouponCode{}

No Hooks.

Returns

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->render( $attributes, $content, $block );
$attributes(array) (required)
Block attributes.
$content(string) (required)
Block content.
$block(WP_Block|null) (required)
Block instance.

CouponCode::render() code WC 10.8.1

protected function render( $attributes, $content, $block ) {
	$parsed_block = $block instanceof WP_Block ? $block->parsed_block : array();
	$attributes   = $this->get_block_attributes( $parsed_block, $attributes );
	$source       = $attributes['source'] ?? 'createNew';

	if ( 'createNew' === $source ) {
		$coupon_code = self::COUPON_CODE_PLACEHOLDER;
	} else {
		$coupon_code = $this->get_coupon_code( $attributes );
	}

	if ( empty( $coupon_code ) ) {
		return '';
	}

	$rendering_context = $this->get_rendering_context( $block );
	$coupon_html       = $this->build_coupon_html( $coupon_code, $attributes, $rendering_context );

	return $this->wrap_for_email( $coupon_html, $parsed_block );
}