Automattic\WooCommerce\Blocks\BlockTypes

ProductCategories::render │ protected │ WC 1.0

Render the Product Categories List block.

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

Хуков нет.

Возвращает

string. Rendered block type output.

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

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

Код ProductCategories::render() WC 11.3.0

protected function render( $attributes, $content, $block ) {
	$uid        = uniqid( 'product-categories-' );
	$categories = $this->get_categories( $attributes );

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

	if ( ! empty( $content ) ) {
		// Deal with legacy attributes (before this was an SSR block) that differ from defaults.
		if ( strstr( $content, 'data-has-count="false"' ) ) {
			$attributes['hasCount'] = false;
		}
		if ( strstr( $content, 'data-is-dropdown="true"' ) ) {
			$attributes['isDropdown'] = true;
		}
		if ( strstr( $content, 'data-is-hierarchical="false"' ) ) {
			$attributes['isHierarchical'] = false;
		}
		if ( strstr( $content, 'data-has-empty="true"' ) ) {
			$attributes['hasEmpty'] = true;
		}
	}

	$classes = $this->get_container_classes( $attributes );
	// The editor wrapper already applies block supports and Global Styles.
	// Replace this workaround when Gutenberg exposes HtmlRenderer: https://github.com/WordPress/gutenberg/pull/74228.
	$wrapper_attributes = ! empty( $attributes['isPreview'] )
		? 'class="' . esc_attr( $classes ) . '"'
		: get_block_wrapper_attributes( array( 'class' => $classes ) );

	$output  = '<div ' . $wrapper_attributes . '>';
	$output .= ! empty( $attributes['isDropdown'] ) ? $this->renderDropdown( $categories, $attributes, $uid ) : $this->renderList( $categories, $attributes, $uid );
	$output .= '</div>';

	return $output;
}