Automattic\WooCommerce\Blocks\BlockTypes

ProductCategories::render()protectedWC 1.0

Render the Product Categories List block.

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

Хуков нет.

Возвращает

Строку. Rendered block type output.

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

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

Код ProductCategories::render() WC 6.9.4

protected function render( $attributes, $content ) {
	$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_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes(
		$attributes,
		array( 'line_height', 'text_color', 'font_size' )
	);

	$classes = $this->get_container_classes( $attributes ) . ' ' . $classes_and_styles['classes'];
	$styles  = $classes_and_styles['styles'];

	$output  = '<div class="wp-block-woocommerce-product-categories ' . esc_attr( $classes ) . '" style="' . esc_attr( $styles ) . '">';
	$output .= ! empty( $attributes['isDropdown'] ) ? $this->renderDropdown( $categories, $attributes, $uid ) : $this->renderList( $categories, $attributes, $uid );
	$output .= '</div>';

	return $output;
}