Automattic\WooCommerce\Blocks\BlockTypes
ProductSummary::render
Include and render the block.
Method of the class: ProductSummary{}
No Hooks.
Returns
String
. Rendered block type output.
Usage
// protected - for code of main (parent) or child class $result = $this->render( $attributes, $content, $block );
- $attributes(array) (required)
- Block attributes.
Default: empty array - $content(string) (required)
- Block content.
Default: empty string - $block(WP_Block) (required)
- Block instance.
ProductSummary::render() ProductSummary::render code WC 9.9.4
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'] ?? '' ), $final_summary ); }