Automattic\WooCommerce\Blocks\StoreApi\Schemas
ProductSchema::get_term_list() protected WC 1.0
Returns a list of terms assigned to the product.
{} Это метод класса: ProductSchema{}
Хуков нет.
Возвращает
Массив
. Array of terms (id, name, slug).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_term_list( \WC_Product $product, $taxonomy );
- \WC_Product $product (обязательный)
- -
- $taxonomy(строка)
- Taxonomy name.
Код ProductSchema::get_term_list() ProductSchema::get term list WC 5.2.1
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;
}