Automattic\WooCommerce\StoreApi\Routes\V1\Ucp

CatalogSearch::resolve_category_slugs │ private │ WC 1.0

Resolve category references to the term slugs ProductQuery filters on.

ProductQuery types a category list from its first element, so a request mixing ids and slugs is normalized to slugs here. The list is deduplicated and capped: one request must not drive an unbounded number of term lookups on an unauthenticated endpoint.

Метод класса: CatalogSearch{}

Хуков нет.

Возвращает

array.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->resolve_category_slugs( $references ): array;
$references(массив) (обязательный)
Category term ids or slugs.

Код CatalogSearch::resolve_category_slugs() WC 11.3.0

private function resolve_category_slugs( array $references ): array {
	$slugs = array();

	foreach ( array_slice( array_unique( $references ), 0, self::MAX_CATEGORY_FILTERS ) as $reference ) {
		$reference = (string) $reference;
		$term      = ctype_digit( $reference )
			? get_term_by( 'id', (int) $reference, 'product_cat' )
			: get_term_by( 'slug', $reference, 'product_cat' );

		if ( $term instanceof \WP_Term ) {
			$slugs[] = $term->slug;
		}
	}

	return $slugs;
}