WC_REST_Products_V2_Controller::get_taxonomy_terms()protectedWC 1.0

Get taxonomy terms.

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

Хуков нет.

Возвращает

Массив.

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

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

Код WC_REST_Products_V2_Controller::get_taxonomy_terms() WC 8.7.0

protected function get_taxonomy_terms( $product, $taxonomy = 'cat' ) {
	$terms = array();

	foreach ( wc_get_object_terms( $product->get_id(), 'product_' . $taxonomy ) as $term ) {
		$terms[] = array(
			'id'   => $term->term_id,
			'name' => $term->name,
			'slug' => $term->slug,
		);
	}

	return $terms;
}