Automattic\WooCommerce\StoreApi\Schemas\V1
ShopperListItemSchema::get_image_html
Get the thumbnail image HTML for a shopper list item, falling back to the WooCommerce placeholder when the product has no image or has been deleted.
Pre-formatting on the server lets renderers (PHP SSR + JS hydration) consume one canonical string instead of each side composing the markup from the structured images array. Mirrors the pattern WC uses in ProductSchema::price_html / ProductImage::render.
Method of the class: ShopperListItemSchema{}
No Hooks.
Returns
String.
Usage
// private - for code of main (parent) class only $result = $this->get_image_html( ?\WC_Product $product ): string;
- ?\WC_Product $product(required)
- .
ShopperListItemSchema::get_image_html() ShopperListItemSchema::get image html code WC 10.9.4
private function get_image_html( ?\WC_Product $product ): string {
$image_id = $product instanceof \WC_Product ? (int) $product->get_image_id() : 0;
if ( $image_id > 0 ) {
return (string) wp_get_attachment_image( $image_id, 'woocommerce_thumbnail' );
}
return (string) wc_placeholder_img( 'woocommerce_thumbnail' );
}