Automattic\WooCommerce\Blocks\BlockTypes

ProductImage::renderprotectedWC 1.0

Include and render the block

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

Хуков нет.

Возвращает

Строку. 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.

Код ProductImage::render() WC 9.9.3

protected function render( $attributes, $content, $block ) {
	if ( ! empty( $content ) ) {
		parent::register_block_type_assets();
		$this->register_chunk_translations( [ $this->block_name ] );
		return $content;
	}
	$parsed_attributes = $this->parse_attributes( $attributes );

	$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array(), array( 'extra_classes' ) );

	$post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : '';
	$product = wc_get_product( $post_id );

	$classes = implode(
		' ',
		array_filter(
			array(
				'wc-block-components-product-image wc-block-grid__product-image',
				esc_attr( $classes_and_styles['classes'] ),
			)
		)
	);

	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'class' => $classes,
			'style' => esc_attr( $classes_and_styles['styles'] ),
		)
	);

	if ( $product ) {
		return sprintf(
			'<div %1$s>
				%2$s
			</div>',
			$wrapper_attributes,
			$this->render_anchor(
				$product,
				$this->render_on_sale_badge( $product, $parsed_attributes ),
				$this->render_image( $product, $parsed_attributes ),
				$parsed_attributes
			)
		);

	}
}