WC_API_Products::get_product_attribute_terms()
Get a listing of product attribute terms.
Метод класса: WC_API_Products{}
Хуки из метода
Возвращает
Массив|WP_Error
.
Использование
$WC_API_Products = new WC_API_Products(); $WC_API_Products->get_product_attribute_terms( $attribute_id, $fields );
- $attribute_id(int) (обязательный)
- Attribute ID.
- $fields(строка|null)
- Fields to limit response to.
По умолчанию: null
Список изменений
С версии 2.5.0 | Введена. |
Код WC_API_Products::get_product_attribute_terms() WC API Products::get product attribute terms WC 7.7.0
public function get_product_attribute_terms( $attribute_id, $fields = null ) { try { // Permissions check. if ( ! current_user_can( 'manage_product_terms' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_product_attribute_terms', __( 'You do not have permission to read product attribute terms', 'woocommerce' ), 401 ); } $attribute_id = absint( $attribute_id ); $taxonomy = wc_attribute_taxonomy_name_by_id( $attribute_id ); if ( ! $taxonomy ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_attribute_id', __( 'A product attribute with the provided ID could not be found', 'woocommerce' ), 404 ); } $terms = get_terms( $taxonomy, array( 'hide_empty' => false ) ); $attribute_terms = array(); foreach ( $terms as $term ) { $attribute_terms[] = array( 'id' => $term->term_id, 'slug' => $term->slug, 'name' => $term->name, 'count' => $term->count, ); } return array( 'product_attribute_terms' => apply_filters( 'woocommerce_api_product_attribute_terms_response', $attribute_terms, $terms, $fields, $this ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } }