$key ) { $value = null !== $getPostMeta ? $getPostMeta( $productId, $key, true ) : get_post_meta( $productId, $key, true ); if ( $value ) { $types[] = $type; } } return $types; } public static function annotateProducts( array $products, ?callable $getPostMeta = null ): array { $ids = array(); foreach ( $products as $product ) { if ( is_array( $product ) && isset( $product['id'] ) && is_int( $product['id'] ) ) { $ids[] = $product['id']; } } if ( ! empty( $ids ) && function_exists( 'update_meta_cache' ) ) { update_meta_cache( 'post', array_values( array_unique( $ids ) ) ); } foreach ( $products as $index => $product ) { if ( is_array( $product ) && isset( $product['id'] ) && is_int( $product['id'] ) ) { $products[ $index ]['aiMarkedTypes'] = self::markedTypes( (int) $product['id'], $getPostMeta ); } } return $products; } }