diff --git a/includes/abstracts/abstract-wc-product.php b/includes/abstracts/abstract-wc-product.php
index 0713609b25b..0bdd4c0b775 100644
--- a/includes/abstracts/abstract-wc-product.php
+++ b/includes/abstracts/abstract-wc-product.php
@@ -1347,6 +1347,21 @@ class WC_Product {
) );
}
+ /**
+ * Gets the main product image ID.
+ * @return int
+ */
+ public function get_image_id() {
+ if ( has_post_thumbnail( $this->id ) ) {
+ $image_id = get_post_thumbnail_id( $this->id );
+ } elseif ( ( $parent_id = wp_get_post_parent_id( $this->id ) ) && has_post_thumbnail( $parent_id ) ) {
+ $image_id = get_post_thumbnail_id( $parent_id );
+ } else {
+ $image_id = 0;
+ }
+ return $image_id;
+ }
+
/**
* Returns the main product image
*
diff --git a/includes/class-wc-product-variation.php b/includes/class-wc-product-variation.php
index d3eafa83984..28da811cc5b 100644
--- a/includes/class-wc-product-variation.php
+++ b/includes/class-wc-product-variation.php
@@ -321,6 +321,23 @@ class WC_Product_Variation extends WC_Product {
return apply_filters( 'woocommerce_get_variation_price_html', $price, $this );
}
+ /**
+ * Gets the main product image ID.
+ * @return int
+ */
+ public function get_image_id() {
+ if ( $this->variation_id && has_post_thumbnail( $this->variation_id ) ) {
+ $image_id = get_post_thumbnail_id( $this->variation_id );
+ } elseif ( has_post_thumbnail( $this->id ) ) {
+ $image_id = get_post_thumbnail_id( $this->id );
+ } elseif ( ( $parent_id = wp_get_post_parent_id( $this->id ) ) && has_post_thumbnail( $parent_id ) ) {
+ $image_id = get_post_thumbnail_id( $parent_id );
+ } else {
+ $image_id = 0;
+ }
+ return $image_id;
+ }
+
/**
* Gets the main product image.
*
@@ -329,10 +346,6 @@ class WC_Product_Variation extends WC_Product {
* @return string
*/
public function get_image( $size = 'shop_thumbnail', $attr = array() ) {
- global $woocommerce;
-
- $image = '';
-
if ( $this->variation_id && has_post_thumbnail( $this->variation_id ) ) {
$image = get_the_post_thumbnail( $this->variation_id, $size, $attr );
} elseif ( has_post_thumbnail( $this->id ) ) {
diff --git a/templates/emails/email-order-items.php b/templates/emails/email-order-items.php
index 82fa567a50a..b05f66a09ad 100644
--- a/templates/emails/email-order-items.php
+++ b/templates/emails/email-order-items.php
@@ -22,7 +22,7 @@ foreach ( $items as $item ) :
// Show title/image etc
if ( $show_image ) {
- echo apply_filters( 'woocommerce_order_item_thumbnail', '', $item );
+ echo apply_filters( 'woocommerce_order_item_thumbnail', '', $item );
}
// Product name