Automattic\WooCommerce\Blocks\BlockTypes

ProductDescription::render │ protected │ WC 1.0

Render the block.

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

Хуки из метода

Возвращает

string. Rendered block output.

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

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

Код ProductDescription::render() WC 11.2.2

protected function render( $attributes, $content, $block ) {
	// Check if we have a product ID in context.
	if ( ! isset( $block->context['postId'] ) ) {
		return '';
	}

	$product_id = absint( $block->context['postId'] );

	// Get the product.
	$product = wc_get_product( $product_id );
	if ( ! $product ) {
		return '';
	}

	$description = ProductDescriptionUtils::guarded_format(
		$product,
		function () use ( $product ) {
			/**
			 * This filter is documented in wp-includes/post-template.php.
			 * We follow core/content block to replace ]]> with ]>
			 */
			// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
			return apply_filters( 'the_content', str_replace( ']]>', ']]>', $product->get_description() ) );
		}
	);

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

	// Add wrapper with block attributes.
	$wrapper_attributes = get_block_wrapper_attributes(
		array( 'class' => 'wc-block-product-description' )
	);

	return sprintf(
		'<div %1$s>%2$s</div>',
		$wrapper_attributes,
		$description
	);
}