*/ public function resolve( array $product_ids ): array { $ids = array_values( array_unique( array_filter( array_map( 'absint', $product_ids ) ) ) ); if ( empty( $ids ) ) { return array(); } if ( function_exists( '_prime_post_caches' ) ) { _prime_post_caches( $ids, false, false ); } if ( function_exists( 'update_meta_cache' ) ) { update_meta_cache( 'post', $ids ); } $thumbnail_ids = array(); foreach ( $ids as $id ) { $thumbnail_ids[ $id ] = (int) get_post_meta( $id, '_thumbnail_id', true ); } $attachment_ids = array_values( array_unique( array_filter( $thumbnail_ids ) ) ); if ( ! empty( $attachment_ids ) ) { if ( function_exists( '_prime_post_caches' ) ) { _prime_post_caches( $attachment_ids, false, false ); } if ( function_exists( 'update_meta_cache' ) ) { update_meta_cache( 'post', $attachment_ids ); } } $out = array(); foreach ( $ids as $id ) { $out[ $id ] = array( 'name' => $this->readName( $id ), 'sku' => (string) get_post_meta( $id, '_sku', true ), 'thumbnail_url' => $this->readThumbnailUrl( $thumbnail_ids[ $id ] ), ); } return $out; } private function readName( int $post_id ): string { $title = function_exists( 'get_the_title' ) ? get_the_title( $post_id ) : ''; if ( '' === $title ) { return ''; } return html_entity_decode( wp_strip_all_tags( $title ), ENT_QUOTES | ENT_HTML5, 'UTF-8' ); } private function readThumbnailUrl( int $attachment_id ): ?string { if ( $attachment_id <= 0 || ! function_exists( 'wp_get_attachment_image_url' ) ) { return null; } $url = wp_get_attachment_image_url( $attachment_id, 'thumbnail' ); return is_string( $url ) && '' !== $url ? $url : null; } }