Automattic\WooCommerce\Internal\Utilities
ProductUtil::prime_image_caches
Prime featured and gallery image attachment caches for a collection of products in a single batched query, instead of priming each product's images separately.
Метод класса: ProductUtil{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
$ProductUtil = new ProductUtil(); $ProductUtil->prime_image_caches( $products ): void;
- $products(массив) (обязательный)
- Products whose image attachments should be primed. Non-product items are ignored.
Код ProductUtil::prime_image_caches() ProductUtil::prime image caches WC 11.2.2
public function prime_image_caches( array $products ): void {
$products = array_filter( $products, static fn( $product ) => $product instanceof \WC_Product );
$featured = array_map( static fn( $product ) => $product->get_image_id(), $products );
$gallery = array_map( static fn( $product ) => $product->get_gallery_image_ids(), $products );
$image_ids = array_filter( array_unique( array_map( 'intval', array_merge( $featured, ...$gallery ) ) ) );
if ( ! empty( $image_ids ) ) {
// Prime caches to reduce future queries.
_prime_post_caches( $image_ids );
}
}