Merge pull request #27289 from woocommerce/fix/27222
use first gallery image on single product when image not assigned
This commit is contained in:
commit
67a54b3aa3
|
@ -1475,7 +1475,15 @@ 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wc_get_template( 'single-product/product-thumbnails.php', array( 'post_thumbnail_id' => $post_thumbnail_id ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ! function_exists( 'woocommerce_show_product_thumbnails' ) ) {
|
if ( ! function_exists( 'woocommerce_show_product_thumbnails' ) ) {
|
||||||
|
@ -1484,7 +1492,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 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
*
|
*
|
||||||
* @see https://docs.woocommerce.com/document/template-structure/
|
* @see https://docs.woocommerce.com/document/template-structure/
|
||||||
* @package WooCommerce\Templates
|
* @package WooCommerce\Templates
|
||||||
* @version 3.5.1
|
* @version 4.6.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
@ -25,12 +25,11 @@ 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();
|
|
||||||
$wrapper_classes = apply_filters(
|
$wrapper_classes = apply_filters(
|
||||||
'woocommerce_single_product_image_gallery_classes',
|
'woocommerce_single_product_image_gallery_classes',
|
||||||
array(
|
array(
|
||||||
'woocommerce-product-gallery',
|
'woocommerce-product-gallery',
|
||||||
'woocommerce-product-gallery--' . ( $product->get_image_id() ? 'with-images' : 'without-images' ),
|
'woocommerce-product-gallery--' . ( $post_thumbnail_id ? 'with-images' : 'without-images' ),
|
||||||
'woocommerce-product-gallery--columns-' . absint( $columns ),
|
'woocommerce-product-gallery--columns-' . absint( $columns ),
|
||||||
'images',
|
'images',
|
||||||
)
|
)
|
||||||
|
@ -39,7 +38,7 @@ $wrapper_classes = apply_filters(
|
||||||
<div class="<?php echo esc_attr( implode( ' ', array_map( 'sanitize_html_class', $wrapper_classes ) ) ); ?>" data-columns="<?php echo esc_attr( $columns ); ?>" style="opacity: 0; transition: opacity .25s ease-in-out;">
|
<div class="<?php echo esc_attr( implode( ' ', array_map( 'sanitize_html_class', $wrapper_classes ) ) ); ?>" data-columns="<?php echo esc_attr( $columns ); ?>" style="opacity: 0; transition: opacity .25s ease-in-out;">
|
||||||
<figure class="woocommerce-product-gallery__wrapper">
|
<figure class="woocommerce-product-gallery__wrapper">
|
||||||
<?php
|
<?php
|
||||||
if ( $product->get_image_id() ) {
|
if ( $post_thumbnail_id ) {
|
||||||
$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">';
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
*
|
*
|
||||||
* @see https://docs.woocommerce.com/document/template-structure/
|
* @see https://docs.woocommerce.com/document/template-structure/
|
||||||
* @package WooCommerce\Templates
|
* @package WooCommerce\Templates
|
||||||
* @version 3.5.1
|
* @version 4.6.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
@ -24,9 +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 && $product->get_image_id() ) {
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue