WC_API_Products::get_product_attributes() public WC 2.4.0
Get a listing of product attributes
{} Это метод класса: WC_API_Products{}
Хуки из метода
Возвращает
Массив/WP_Error.
Использование
$WC_API_Products = new WC_API_Products(); $WC_API_Products->get_product_attributes( $fields );
- $fields(строка/null)
- fields to limit response to
Список изменений
С версии 2.4.0 | Введена. |
Код WC_API_Products::get_product_attributes() WC API Products::get product attributes WC 5.0.0
public function get_product_attributes( $fields = null ) {
try {
// Permissions check
if ( ! current_user_can( 'manage_product_terms' ) ) {
throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_product_attributes', __( 'You do not have permission to read product attributes', 'woocommerce' ), 401 );
}
$product_attributes = array();
$attribute_taxonomies = wc_get_attribute_taxonomies();
foreach ( $attribute_taxonomies as $attribute ) {
$product_attributes[] = array(
'id' => intval( $attribute->attribute_id ),
'name' => $attribute->attribute_label,
'slug' => wc_attribute_taxonomy_name( $attribute->attribute_name ),
'type' => $attribute->attribute_type,
'order_by' => $attribute->attribute_orderby,
'has_archives' => (bool) $attribute->attribute_public,
);
}
return array( 'product_attributes' => apply_filters( 'woocommerce_api_product_attributes_response', $product_attributes, $attribute_taxonomies, $fields, $this ) );
} catch ( WC_API_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
}