WC_Product::get_image( string $size = 'woocommerce_thumbnail', array $attr = array(), bool $placeholder = true )
Returns the main product image.
Description Description
Parameters Parameters
- $size
-
(Optional) (default: 'woocommerce_thumbnail').
Default value: 'woocommerce_thumbnail'
- $attr
-
(Optional) Image attributes.
Default value: array()
- $placeholder
-
(Optional) True to return $placeholder if no image is found, or false to return an empty string.
Default value: true
Return Return
(string)
Source Source
File: includes/abstracts/abstract-wc-product.php
public function get_image( $size = 'woocommerce_thumbnail', $attr = array(), $placeholder = true ) { $image = ''; if ( $this->get_image_id() ) { $image = wp_get_attachment_image( $this->get_image_id(), $size, false, $attr ); } elseif ( $this->get_parent_id() ) { $parent_product = wc_get_product( $this->get_parent_id() ); if ( $parent_product ) { $image = $parent_product->get_image( $size, $attr, $placeholder ); } } if ( ! $image && $placeholder ) { $image = wc_placeholder_img( $size, $attr ); } return apply_filters( 'woocommerce_product_get_image', $image, $this, $size, $attr, $placeholder, $image ); }