wc_render_product_image_template_for_image_ids()
Render the product-image template using a caller-supplied image set instead of the product's stored featured + gallery.
Used by the variation gallery swap path: the variation has its own ordered list of images, but we still want the parent product's gallery template to render them so theme overrides and woocommerce_product_thumbnails apply uniformly. We achieve this by hooking the product's get_image_id / get_gallery_image_ids filters for the duration of the render; the template sees the substituted values and is none the wiser.
Хуков нет.
Возвращает
Строку.
Использование
wc_render_product_image_template_for_image_ids( $product, $image_ids ): string;
- $product(WC_Product) (обязательный)
- Product being rendered.
- $image_ids(разное) (обязательный)
- Image IDs to substitute. Will be normalized.
Список изменений
| С версии 10.8.0 | Введена. |
Код wc_render_product_image_template_for_image_ids() wc render product image template for image ids WC 11.0.1
function wc_render_product_image_template_for_image_ids( WC_Product $product, $image_ids ): string {
$normalized = array_values( array_unique( array_map( 'intval', array_filter( (array) $image_ids ) ) ) );
$featured_id = $normalized[0] ?? 0;
$gallery_ids = array_slice( $normalized, 1 );
$remove_overrides = wc_apply_product_image_overrides( $product, $featured_id, $gallery_ids );
try {
return wc_render_product_image_template_for( $product );
} finally {
$remove_overrides();
}
}