From 41d53a98804212782d347260009668316ff34a3b Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Tue, 11 Aug 2020 13:33:47 -0300 Subject: [PATCH 1/3] use first gallery image on single product when image not assigned --- templates/single-product/product-image.php | 12 +++++++++--- templates/single-product/product-thumbnails.php | 7 +++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/templates/single-product/product-image.php b/templates/single-product/product-image.php index 0399028c8d8..12c1483a44b 100644 --- a/templates/single-product/product-image.php +++ b/templates/single-product/product-image.php @@ -12,7 +12,7 @@ * * @see https://docs.woocommerce.com/document/template-structure/ * @package WooCommerce\Templates - * @version 3.5.1 + * @version 4.5.0 */ defined( 'ABSPATH' ) || exit; @@ -26,11 +26,17 @@ global $product; $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( 'woocommerce_single_product_image_gallery_classes', array( '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 ), 'images', ) @@ -39,7 +45,7 @@ $wrapper_classes = apply_filters(