Automattic\WooCommerce\Blocks\BlockTypes

ProductImage::render()protectedWC 1.0

Include and render the block

Method of the class: ProductImage{}

No Hooks.

Return

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.

ProductImage::render() code WC 9.5.1

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
			)
		);

	}
}