Automattic\WooCommerce\Blocks\BlockTypes

CategoryDescription::render │ protected │ WC 1.0

Render the block.

Метод класса: CategoryDescription{}

Хуков нет.

Возвращает

string. Rendered block output.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->render( $attributes, $content, $block );
$attributes(массив) (обязательный)
Block attributes.
$content(строка) (обязательный)
Block content.
$block(WP_Block) (обязательный)
Block instance.

Код CategoryDescription::render() WC 11.3.0

protected function render( $attributes, $content, $block ) {
	$term_id       = $block->context['termId'] ?? 0;
	$term_taxonomy = $block->context['termTaxonomy'] ?? $block->context['taxonomy'] ?? 'product_cat';

	$text_align = isset( $attributes['textAlign'] ) ? sanitize_key( $attributes['textAlign'] ) : '';

	if ( ! $term_id ) {
		return '';
	}

	$term = get_term( $term_id, $term_taxonomy );
	if ( ! $term || is_wp_error( $term ) ) {
		return '';
	}

	$description = $term->description;
	if ( empty( trim( $description ) ) ) {
		return '';
	}

	$classes = array();
	if ( $text_align ) {
		$classes[] = 'has-text-align-' . $text_align;
	}

	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'class' => implode( ' ', $classes ),
		)
	);

	return sprintf(
		'<div %1$s>%2$s</div>',
		$wrapper_attributes,
		wp_kses_post( wc_format_content( $description ) )
	);
}