Automattic\WooCommerce\Blocks\BlockTypes
ProductSummary::render()
Include and render the block.
Метод класса: ProductSummary{}
Хуков нет.
Возвращает
Строку
. Rendered block type output.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
По умолчанию: empty array - $content(строка) (обязательный)
- Block content.
По умолчанию: empty string - $block(WP_Block) (обязательный)
- Block instance.
Код ProductSummary::render() ProductSummary::render WC 9.7.1
protected function render( $attributes, $content, $block ) { if ( ! empty( $content ) ) { parent::register_block_type_assets(); $this->register_chunk_translations( [ $this->block_name ] ); return $content; } $post_id = $block->context['postId'] ?? ''; $product = wc_get_product( $post_id ); if ( ! $product ) { return ''; } $show_description_if_empty = isset( $attributes['showDescriptionIfEmpty'] ) && $attributes['showDescriptionIfEmpty']; $source = $this->get_source( $product, $show_description_if_empty ); if ( ! $source ) { return ''; } $summary_length = isset( $attributes['summaryLength'] ) ? $attributes['summaryLength'] : false; $link_text = isset( $attributes['linkText'] ) ? $attributes['linkText'] : ''; $show_link = isset( $attributes['showLink'] ) && $attributes['showLink']; $summary = $summary_length ? $this->generate_summary( $source, $summary_length ) : wpautop( $source ); $final_summary = $show_link && $link_text ? $summary . $this->create_anchor( $product, $link_text ) : $summary; $styles_and_classes = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes ); return sprintf( '<div class="wp-block-woocommerce-product-summary"><div class="wc-block-components-product-summary %1$s" style="%2$s"> %3$s </div></div>', esc_attr( $styles_and_classes['classes'] ), esc_attr( $styles_and_classes['styles'] ?? '' ), wp_kses_post( $final_summary ) ); }