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 11.0.1
protected function render( $attributes, $content, $block ) {
$post_id = $block->context['postId'] ?? '';
$product = wc_get_product( $post_id );
if ( ! $product || post_password_required( $product->get_id() ) ) {
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'] ?? '' ),
$final_summary
);
}