wc_render_product_image_template_for()WC 10.8.0

Render the single-product/product-image.php template for a given product.

Temporarily promotes $product into $GLOBALS['product'] so the template, which reads from globals, sees the right object. Restores the previous global before returning.

Хуков нет.

Возвращает

Строку.

Использование

wc_render_product_image_template_for( $product ): string;
$product(WC_Product) (обязательный)
Product to render.

Список изменений

С версии 10.8.0 Введена.

Код wc_render_product_image_template_for() WC 10.9.1

function wc_render_product_image_template_for( WC_Product $product ): string {
	$had_previous_product = array_key_exists( 'product', $GLOBALS );
	$previous_product     = $had_previous_product ? $GLOBALS['product'] : null;
	$GLOBALS['product']   = $product;

	try {
		return trim( wc_get_template_html( 'single-product/product-image.php' ) );
	} finally {
		if ( $had_previous_product ) {
			$GLOBALS['product'] = $previous_product;
		} else {
			unset( $GLOBALS['product'] );
		}
	}
}