wc_get_gallery_image_html checks
This commit is contained in:
parent
67bef92657
commit
280ca3757e
|
@ -1053,6 +1053,8 @@ if ( ! function_exists( 'woocommerce_show_product_thumbnails' ) ) {
|
||||||
/**
|
/**
|
||||||
* Get HTML for a gallery image.
|
* Get HTML for a gallery image.
|
||||||
*
|
*
|
||||||
|
* woocommerce_gallery_thumbnail_size, woocommerce_gallery_image_size and woocommerce_gallery_full_size accept name based image sizes, or an array of width/height values.
|
||||||
|
*
|
||||||
* @since 3.3.2
|
* @since 3.3.2
|
||||||
* @param int $attachment_id
|
* @param int $attachment_id
|
||||||
* @param bool $main_image Is this the main image or a thumbnail?
|
* @param bool $main_image Is this the main image or a thumbnail?
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
// Note: `wc_get_gallery_image_html` was added in WC 3.3.2 and did not exist prior. This check protects against theme overrides being used on older versions of WC.
|
||||||
|
if ( ! function_exists( 'wc_get_gallery_image_html' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
global $product;
|
global $product;
|
||||||
|
|
||||||
$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 4 );
|
$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 4 );
|
||||||
|
@ -33,7 +38,6 @@ $wrapper_classes = apply_filters( 'woocommerce_single_product_image_gallery_cl
|
||||||
<figure class="woocommerce-product-gallery__wrapper">
|
<figure class="woocommerce-product-gallery__wrapper">
|
||||||
<?php
|
<?php
|
||||||
if ( has_post_thumbnail() ) {
|
if ( has_post_thumbnail() ) {
|
||||||
// Note: `wc_get_gallery_image_html` was added in WC 3.3.2 and did not exist prior.
|
|
||||||
$html = wc_get_gallery_image_html( $post_thumbnail_id, true );
|
$html = wc_get_gallery_image_html( $post_thumbnail_id, true );
|
||||||
} else {
|
} else {
|
||||||
$html = '<div class="woocommerce-product-gallery__image--placeholder">';
|
$html = '<div class="woocommerce-product-gallery__image--placeholder">';
|
||||||
|
|
|
@ -18,13 +18,17 @@
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
// Note: `wc_get_gallery_image_html` was added in WC 3.3.2 and did not exist prior. This check protects against theme overrides being used on older versions of WC.
|
||||||
|
if ( ! function_exists( 'wc_get_gallery_image_html' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
global $product;
|
global $product;
|
||||||
|
|
||||||
$attachment_ids = $product->get_gallery_image_ids();
|
$attachment_ids = $product->get_gallery_image_ids();
|
||||||
|
|
||||||
if ( $attachment_ids && has_post_thumbnail() ) {
|
if ( $attachment_ids && has_post_thumbnail() ) {
|
||||||
foreach ( $attachment_ids as $attachment_id ) {
|
foreach ( $attachment_ids as $attachment_id ) {
|
||||||
// Note: `wc_get_gallery_image_html` was added in WC 3.3.2 and did not exist prior.
|
|
||||||
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', wc_get_gallery_image_html( $attachment_id ), $attachment_id );
|
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', wc_get_gallery_image_html( $attachment_id ), $attachment_id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue