Automattic\WooCommerce\Blocks\BlockTypes
CouponCode::render
Render the coupon code block.
Метод класса: CouponCode{}
Хуков нет.
Возвращает
string.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
- $content(строка) (обязательный)
- Block content.
- $block(WP_Block|null) (обязательный)
- Block instance.
Код CouponCode::render() CouponCode::render WC 11.3.0
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 );
}