move image id logic to woocommerce_show_product_*

This commit is contained in:
Ron Rennick 2020-08-12 15:31:27 -03:00
parent 41d53a9880
commit 84d6d6c525
3 changed files with 17 additions and 14 deletions

View File

@ -1473,7 +1473,16 @@ if ( ! function_exists( 'woocommerce_show_product_images' ) ) {
* Output the product image before the single product summary. * Output the product image before the single product summary.
*/ */
function woocommerce_show_product_images() { function woocommerce_show_product_images() {
wc_get_template( 'single-product/product-image.php' ); global $product;
$post_thumbnail_id = $product->get_image_id();
if ( ! $post_thumbnail_id ) {
$gallery_image_ids = $product->get_gallery_image_ids();
if ( ! empty( $gallery_image_ids ) ) {
$post_thumbnail_id = array_shift( $gallery_image_ids );
}
}
$args = compact( 'post_thumbnail_id', 'gallery_image_ids' );
wc_get_template( 'single-product/product-image.php', $args );
} }
} }
if ( ! function_exists( 'woocommerce_show_product_thumbnails' ) ) { if ( ! function_exists( 'woocommerce_show_product_thumbnails' ) ) {
@ -1482,7 +1491,13 @@ if ( ! function_exists( 'woocommerce_show_product_thumbnails' ) ) {
* Output the product thumbnails. * Output the product thumbnails.
*/ */
function woocommerce_show_product_thumbnails() { function woocommerce_show_product_thumbnails() {
wc_get_template( 'single-product/product-thumbnails.php' ); global $product;
$attachment_ids = $product->get_gallery_image_ids();
if ( $attachment_ids && ! $product->get_image_id() ) {
array_shift( $attachment_ids );
}
wc_get_template( 'single-product/product-thumbnails.php', array( 'attachment_ids' => $attachment_ids ) );
} }
} }

View File

@ -25,13 +25,6 @@ if ( ! function_exists( 'wc_get_gallery_image_html' ) ) {
global $product; global $product;
$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 4 ); $columns = apply_filters( 'woocommerce_product_thumbnails_columns', 4 );
$post_thumbnail_id = $product->get_image_id();
if ( ! $post_thumbnail_id ) {
$gallery_image_ids = $product->get_gallery_image_ids();
if ( ! empty( $gallery_image_ids ) ) {
$post_thumbnail_id = array_shift( $gallery_image_ids );
}
}
$wrapper_classes = apply_filters( $wrapper_classes = apply_filters(
'woocommerce_single_product_image_gallery_classes', 'woocommerce_single_product_image_gallery_classes',
array( array(

View File

@ -24,12 +24,7 @@ if ( ! function_exists( 'wc_get_gallery_image_html' ) ) {
global $product; global $product;
$attachment_ids = $product->get_gallery_image_ids();
if ( $attachment_ids ) { if ( $attachment_ids ) {
if ( ! $product->get_image_id() ) {
array_shift( $attachment_ids );
}
foreach ( $attachment_ids as $attachment_id ) { foreach ( $attachment_ids as $attachment_id ) {
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', wc_get_gallery_image_html( $attachment_id ), $attachment_id ); // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', wc_get_gallery_image_html( $attachment_id ), $attachment_id ); // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped
} }