Automattic\WooCommerce\Blocks\Utils

ProductGalleryUtils::get_media_src_data │ public static │ WC 1.0

Get media source data.

Method of the class: ProductGalleryUtils{}

No Hooks.

Returns

array[]. An array of media source data.

Usage

$result = ProductGalleryUtils::get_media_src_data( $media_items, $size, $product_title );
$media_items(array[]) (required)
Product gallery media items.
$size(string) (required)
The size of the poster/image to retrieve.
$product_title(string)
The title of the product used for alt fallback.
Default: ''

ProductGalleryUtils::get_media_src_data() code WC 11.1.2

public static function get_media_src_data( $media_items, $size, $product_title = '' ) {
	$media_src_data = array();

	foreach ( $media_items as $index => $media_item ) {
		if ( 'video' === ( $media_item['media_type'] ?? '' ) ) {
			$media_src_data[] = self::get_video_data( $media_item, $size, $product_title, $index );
			continue;
		}

		$media_src_data[] = array_merge(
			self::get_image_data( $media_item['id'] ?? 0, $size, $product_title, $index ),
			array( 'media_type' => 'image' )
		);
	}

	return $media_src_data;
}