Automattic\WooCommerce\StoreApi\Schemas\V1

ProductSchema::get_term_list()protectedWC 1.0

Returns a list of terms assigned to the product.

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

Хуков нет.

Возвращает

Массив. Array of terms (id, name, slug).

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_term_list( $product, $taxonomy );
$product(\WC_Product) (обязательный)
Product object.
$taxonomy(строка)
Taxonomy name.
По умолчанию: ''

Код ProductSchema::get_term_list() WC 8.7.0

protected function get_term_list( \WC_Product $product, $taxonomy = '' ) {
	if ( ! $taxonomy ) {
		return [];
	}

	$terms = get_the_terms( $product->get_id(), $taxonomy );

	if ( ! $terms || is_wp_error( $terms ) ) {
		return [];
	}

	$return           = [];
	$default_category = (int) get_option( 'default_product_cat', 0 );

	foreach ( $terms as $term ) {
		$link = get_term_link( $term, $taxonomy );

		if ( is_wp_error( $link ) ) {
			continue;
		}

		if ( $term->term_id === $default_category ) {
			continue;
		}

		$return[] = (object) [
			'id'   => $term->term_id,
			'name' => $term->name,
			'slug' => $term->slug,
			'link' => $link,
		];
	}

	return $return;
}