wc_render_product_image_template_for()
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.
No Hooks.
Returns
String.
Usage
wc_render_product_image_template_for( $product ): string;
- $product(WC_Product) (required)
- Product to render.
Changelog
| Since 10.8.0 | Introduced. |
wc_render_product_image_template_for() wc render product image template for code 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'] );
}
}
}