Automattic\WooCommerce\Internal\ProductGallery
ProductMediaGallery::get_product_media_gallery_items
Get ordered media gallery items for a product.
Method of the class: ProductMediaGallery{}
No Hooks.
Returns
array.
Usage
$result = ProductMediaGallery::get_product_media_gallery_items( $product, $args ): array;
- $product(WC_Product) (required)
- Product object.
- $args(array)
- Optional arguments.
Default:array()
ProductMediaGallery::get_product_media_gallery_items() ProductMediaGallery::get product media gallery items code WC 11.1.2
public static function get_product_media_gallery_items( WC_Product $product, array $args = array() ): array {
$args = wp_parse_args(
$args,
array(
'context' => 'view',
'include_product_image' => true,
'include_placeholder' => false,
'resolve_video_posters' => true,
'deduplicate' => false,
)
);
$context = is_string( $args['context'] ) ? $args['context'] : 'view';
$include_product_image = (bool) $args['include_product_image'];
$media_items = self::get_product_image_media_items( $product, $include_product_image, $context );
if ( self::is_feature_enabled() ) {
$video_gallery = self::normalize_video_gallery_items(
self::get_stored_video_gallery_items( $product )
);
if ( ! empty( $video_gallery ) ) {
$media_items = self::merge_positioned_video_gallery_items(
$media_items,
$video_gallery,
self::get_video_position_offset( $product, $include_product_image, $context )
);
}
}
if ( $args['deduplicate'] ) {
$media_items = self::deduplicate_media_items( $media_items );
}
if ( $args['resolve_video_posters'] ) {
$media_items = self::resolve_video_poster_ids( $media_items );
}
if ( $args['include_placeholder'] && empty( $media_items ) ) {
$media_items[] = array(
'media_type' => 'image',
'source_type' => 'placeholder',
'id' => 0,
);
}
return array_values( $media_items );
}