From 90c987af70cd414d1b7dee99cf858785baa444ba Mon Sep 17 00:00:00 2001 From: James Kemp Date: Mon, 22 May 2017 22:07:51 +0100 Subject: [PATCH 1/2] Utilise $product method to get thumbnail Is there any reason this function isn't using the `get_image()` method? It seems if we're accessing the `$post->ID`, then we should have access to the `$product` object too? The reason being, the `get_image()` method also checks for the parent featured image, so is more robust. It may also be worth considering a filter in the `get_image()` method. --- includes/wc-template-functions.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index e879e09a8c8..e16cc6ac38e 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -768,18 +768,11 @@ if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) { * @return string */ function woocommerce_get_product_thumbnail( $size = 'shop_catalog', $deprecated1 = 0, $deprecated2 = 0 ) { - global $post; + global $product; + $image_size = apply_filters( 'single_product_archive_thumbnail_size', $size ); - if ( has_post_thumbnail() ) { - $props = wc_get_product_attachment_props( get_post_thumbnail_id(), $post ); - return get_the_post_thumbnail( $post->ID, $image_size, array( - 'title' => $props['title'], - 'alt' => $props['alt'], - ) ); - } elseif ( wc_placeholder_img_src() ) { - return wc_placeholder_img( $image_size ); - } + return $product->get_image( $image_size ); } } From 002dd935b556f8ac69c982b7f8084695aa93ef69 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 23 May 2017 19:28:35 +0100 Subject: [PATCH 2/2] Check we have a product object --- includes/wc-template-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index e16cc6ac38e..dfaf8d39ac5 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -772,7 +772,7 @@ if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) { $image_size = apply_filters( 'single_product_archive_thumbnail_size', $size ); - return $product->get_image( $image_size ); + return $product ? $product->get_image( $image_size ) : ''; } }