WC_REST_Products_V1_Controller::get_taxonomy_terms()protectedWC 1.0

Get taxonomy terms.

Method of the class: WC_REST_Products_V1_Controller{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_taxonomy_terms( $product, $taxonomy );
$product(WC_Product) (required)
Product instance.
$taxonomy(string)
Taxonomy slug.
Default: 'cat'

WC_REST_Products_V1_Controller::get_taxonomy_terms() code 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;
}