diff --git a/classes/class-wc-product.php b/classes/class-wc-product.php index 802da63e589..1305bfdaa9c 100644 --- a/classes/class-wc-product.php +++ b/classes/class-wc-product.php @@ -1089,16 +1089,22 @@ class WC_Product { /** * Gets the main product image */ - function get_image( $size = 'shop_thumbnail' ) { + function get_image( $size = 'shop_thumbnail', $echo = true ) { global $woocommerce; - if (has_post_thumbnail($this->id)) : - echo get_the_post_thumbnail($this->id, $size); + $output = ''; + if (has_post_thumbnail($this->id)) : + $output = get_the_post_thumbnail($this->id, $size); elseif (($parent_id = wp_get_post_parent_id( $this->id )) && has_post_thumbnail($parent_id)) : - echo get_the_post_thumbnail($parent_id, $size); + $output = get_the_post_thumbnail($parent_id, $size); else : - echo 'Placeholder'; + $output = 'Placeholder'; endif; + + if ( $echo ) { + echo $output; + } + return $output; } /** diff --git a/templates/cart/cart.php b/templates/cart/cart.php index 721c004ef67..2656b43c472 100755 --- a/templates/cart/cart.php +++ b/templates/cart/cart.php @@ -41,7 +41,7 @@ global $woocommerce; get_image(), $values, $cart_item_key ); + $thumbnail = apply_filters( 'woocommerce_in_cart_product_thumbnail', $_product->get_image(null, false)/* default size, no output */, $values, $cart_item_key ); printf('%s', esc_url( get_permalink( apply_filters('woocommerce_in_cart_product_id', $values['product_id'] ) ) ), $thumbnail ); ?>