ProductGalleryUtils
in package
Utility methods used for the Product Gallery block.
Table of Contents
- CROP_IMAGE_SIZE_NAME = '_woo_blocks_product_gallery_crop_full'
- get_product_gallery_image_ids() : array<string|int, mixed>
- Get the product gallery image IDs.
- get_product_gallery_images() : array<string|int, mixed>
- When requesting a full-size image, this function may return an array with a single image.
- get_product_image_placeholder_html() : string
- Get the product image placeholder HTML.
- maybe_generate_intermediate_image() : void
- Generates the intermediate image sizes only when needed.
Constants
CROP_IMAGE_SIZE_NAME
public
mixed
CROP_IMAGE_SIZE_NAME
= '_woo_blocks_product_gallery_crop_full'
Methods
get_product_gallery_image_ids()
Get the product gallery image IDs.
public
static get_product_gallery_image_ids(WC_Product $product[, int $max_number_of_visible_images = 8 ][, bool $only_visible = false ]) : array<string|int, mixed>
Parameters
- $product : WC_Product
-
The product object to retrieve the gallery images for.
- $max_number_of_visible_images : int = 8
-
The maximum number of visible images to return. Defaults to 8.
- $only_visible : bool = false
-
Whether to return only the visible images. Defaults to false.
Return values
array<string|int, mixed> — An array of unique image IDs for the product gallery.get_product_gallery_images()
When requesting a full-size image, this function may return an array with a single image.
public
static get_product_gallery_images(int $post_id[, string $size = 'full' ][, array<string|int, mixed> $attributes = array() ][, string $wrapper_class = '' ][, bool $crop_images = false ]) : array<string|int, mixed>
However, when requesting a non-full-size image, it will always return an array with multiple images. This distinction is based on the image size needed for rendering purposes:
- "Full" size is used for the main product featured image.
- Non-full sizes are used for rendering thumbnails.
Parameters
- $post_id : int
-
Post ID.
- $size : string = 'full'
-
Image size.
- $attributes : array<string|int, mixed> = array()
-
Attributes.
- $wrapper_class : string = ''
-
Wrapper class.
- $crop_images : bool = false
-
Whether to crop images.
Return values
array<string|int, mixed> —get_product_image_placeholder_html()
Get the product image placeholder HTML.
public
static get_product_image_placeholder_html(string $size, array<string|int, mixed> $attributes, bool $crop_images) : string
Parameters
- $size : string
-
Image size.
- $attributes : array<string|int, mixed>
-
Attributes.
- $crop_images : bool
-
Whether to crop images.
Return values
string —maybe_generate_intermediate_image()
Generates the intermediate image sizes only when needed.
public
static maybe_generate_intermediate_image(int $attachment_id, string $size) : void
Parameters
- $attachment_id : int
-
Attachment ID.
- $size : string
-
Image size.