Automattic\WooCommerce\StoreApi\Schemas\V1
ProductSchema::get_term_list
Returns a list of terms assigned to the product.
Method of the class: ProductSchema{}
No Hooks.
Returns
Array. Array of terms (id, name, slug).
Usage
// protected - for code of main (parent) or child class $result = $this->get_term_list( $product, $taxonomy );
- $product(WC_Product) (required)
- Product object.
- $taxonomy(string)
- Taxonomy name.
Default:''
ProductSchema::get_term_list() ProductSchema::get term list code WC 10.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;
}