Automattic\WooCommerce\Blocks\BlockTypes

AbstractProductGrid::get_image_html()protectedWC 1.0

Get the product image.

Method of the class: AbstractProductGrid{}

No Hooks.

Return

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_image_html( $product );
$product(\WC_Product) (required)
Product.

AbstractProductGrid::get_image_html() code WC 9.4.2

protected function get_image_html( $product ) {
	if ( array_key_exists( 'image', $this->attributes['contentVisibility'] ) && false === $this->attributes['contentVisibility']['image'] ) {
		return '';
	}

	$attr = array(
		'alt' => '',
	);

	if ( $product->get_image_id() ) {
		$image_alt = get_post_meta( $product->get_image_id(), '_wp_attachment_image_alt', true );
		$attr      = array(
			'alt' => ( $image_alt ? $image_alt : $product->get_name() ),
		);
	}

	return '<div class="wc-block-grid__product-image">' . $product->get_image( 'woocommerce_thumbnail', $attr ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}