Automattic\WooCommerce\Blocks\BlockTypes
FeaturedItem::render_image()
Renders the featured image
Method of the class: FeaturedItem{}
No Hooks.
Return
String
.
Usage
// private - for code of main (parent) class only $result = $this->render_image( $attributes, $item, $image_url );
- $attributes(array) (required)
- Block attributes.
Default: empty array - $item(\WC_Product|\WP_Term) (required)
- Item object.
- $image_url(string) (required)
- Item image url.
FeaturedItem::render_image() FeaturedItem::render image code WC 9.4.2
private function render_image( $attributes, $item, string $image_url ) { $style = sprintf( 'object-fit: %s;', esc_attr( $attributes['imageFit'] ) ); $img_alt = $attributes['alt'] ?: $this->get_item_title( $item ); if ( $this->hasFocalPoint( $attributes ) ) { $style .= sprintf( 'object-position: %s%% %s%%;', $attributes['focalPoint']['x'] * 100, $attributes['focalPoint']['y'] * 100 ); } if ( ! empty( $image_url ) ) { return sprintf( '<img alt="%1$s" class="wc-block-%2$s__background-image" src="%3$s" style="%4$s" />', esc_attr( $img_alt ), $this->block_name, esc_url( $image_url ), esc_attr( $style ) ); } return ''; }