Automattic\WooCommerce\Blocks\BlockTypes

ProductCategories::get_image_html()publicWC 1.0

Returns the category image html

Method of the class: ProductCategories{}

No Hooks.

Return

String.

Usage

$ProductCategories = new ProductCategories();
$ProductCategories->get_image_html( $category, $attributes, $size );
$category(\WP_Term) (required)
Term object.
$attributes(array) (required)
Block attributes.
Default: empty array
$size(string)
Image size.
Default: 'woocommerce_thumbnail'

ProductCategories::get_image_html() code WC 8.7.0

public function get_image_html( $category, $attributes, $size = 'woocommerce_thumbnail' ) {
	if ( empty( $attributes['hasImage'] ) ) {
		return '';
	}

	$image_id = get_term_meta( $category->term_id, 'thumbnail_id', true );

	if ( ! $image_id ) {
		return '<span class="wc-block-product-categories-list-item__image wc-block-product-categories-list-item__image--placeholder">' . wc_placeholder_img( 'woocommerce_thumbnail' ) . '</span>';
	}

	return '<span class="wc-block-product-categories-list-item__image">' . wp_get_attachment_image( $image_id, 'woocommerce_thumbnail' ) . '</span>';
}