parent
8e93f8f286
commit
b97181c08a
|
@ -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
|
* Returns the main product image
|
||||||
*
|
*
|
||||||
|
|
|
@ -321,6 +321,23 @@ class WC_Product_Variation extends WC_Product {
|
||||||
return apply_filters( 'woocommerce_get_variation_price_html', $price, $this );
|
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.
|
* Gets the main product image.
|
||||||
*
|
*
|
||||||
|
@ -329,10 +346,6 @@ class WC_Product_Variation extends WC_Product {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_image( $size = 'shop_thumbnail', $attr = array() ) {
|
public function get_image( $size = 'shop_thumbnail', $attr = array() ) {
|
||||||
global $woocommerce;
|
|
||||||
|
|
||||||
$image = '';
|
|
||||||
|
|
||||||
if ( $this->variation_id && has_post_thumbnail( $this->variation_id ) ) {
|
if ( $this->variation_id && has_post_thumbnail( $this->variation_id ) ) {
|
||||||
$image = get_the_post_thumbnail( $this->variation_id, $size, $attr );
|
$image = get_the_post_thumbnail( $this->variation_id, $size, $attr );
|
||||||
} elseif ( has_post_thumbnail( $this->id ) ) {
|
} elseif ( has_post_thumbnail( $this->id ) ) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ foreach ( $items as $item ) :
|
||||||
|
|
||||||
// Show title/image etc
|
// Show title/image etc
|
||||||
if ( $show_image ) {
|
if ( $show_image ) {
|
||||||
echo apply_filters( 'woocommerce_order_item_thumbnail', '<img src="' . current( wp_get_attachment_image_src( get_post_thumbnail_id( $_product->id ), 'thumbnail') ) .'" alt="' . __( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" />', $item );
|
echo apply_filters( 'woocommerce_order_item_thumbnail', '<img src="' . ( $_product->get_image_id() ? current( wp_get_attachment_image_src( $_product->get_image_id(), 'thumbnail') ) : wc_placeholder_img_src() ) .'" alt="' . __( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" />', $item );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Product name
|
// Product name
|
||||||
|
|
Loading…
Reference in New Issue