WC_Product::get_image
Returns the main product image.
Метод класса: WC_Product{}
Хуки из метода
Возвращает
Строку.
Использование
$WC_Product = new WC_Product(); $WC_Product->get_image( $size, $attr, $placeholder );
- $size(строка)
- .
По умолчанию: 'woocommerce_thumbnail' - $attr(массив)
- Image attributes.
По умолчанию: array() - $placeholder(true|false)
- True to return $placeholder if no image is found, or false to return an empty string.
По умолчанию: true
Код WC_Product::get_image() WC Product::get image WC 10.4.3
public function get_image( $size = 'woocommerce_thumbnail', $attr = array(), $placeholder = true ) {
$image = '';
if ( $this->get_image_id() ) {
$image_alt = get_post_meta( $this->get_image_id(), '_wp_attachment_image_alt', true );
$attr = wp_parse_args(
$attr,
array(
'alt' => $image_alt ? $image_alt : $this->get_name(),
)
);
$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 );
}