*/ public function samples(int $limit = 50): array { if (! function_exists('wc_get_orders')) { return []; } $orders = wc_get_orders([ 'limit' => max(1, $limit), 'orderby' => 'date', 'order' => 'DESC', 'return' => 'objects', ]); if (! is_array($orders)) { return []; } $samples = []; foreach ($orders as $order) { if (! $order instanceof \WC_Order) { continue; } foreach ($order->get_items() as $item) { if (! $item instanceof \WC_Order_Item_Product) { continue; } foreach ($item->get_meta_data() as $metaData) { if (! is_object($metaData) || ! isset($metaData->key)) { continue; } $key = (string) $metaData->key; if (isset($samples[$key]) || MetaSanitizer::isSensitiveKey($key)) { continue; } if (! Options::getBool(Options::INCLUDE_PRIVATE_META) && str_starts_with($key, '_')) { continue; } $samples[$key] = MetaSanitizer::sanitizeValue( $metaData->value ?? '', Options::getInt(Options::MAX_META_VALUE_LENGTH) ?: 1000 ); } } } ksort($samples, SORT_NATURAL | SORT_FLAG_CASE); return $samples; } }