Automattic\WooCommerce\Admin\API
ProductAttributes::format_custom_attribute_items_for_response()
Format custom attribute items for response (mimic the structure of a taxonomy - backed attribute).
Метод класса: ProductAttributes{}
Хуков нет.
Возвращает
Массив
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->format_custom_attribute_items_for_response( $custom_attributes );
- $custom_attributes(массив) (обязательный)
- - CustomAttributeTraits::get_custom_attributes().
Код ProductAttributes::format_custom_attribute_items_for_response() ProductAttributes::format custom attribute items for response WC 9.8.1
protected function format_custom_attribute_items_for_response( $custom_attributes ) { $response = array(); foreach ( $custom_attributes as $attribute_key => $attribute_value ) { $data = array( 'id' => $attribute_key, 'name' => $attribute_value['name'], 'slug' => $attribute_key, 'type' => 'select', 'order_by' => 'menu_order', 'has_archives' => false, ); $item_response = rest_ensure_response( $data ); $item_response->add_links( $this->prepare_links( (object) array( 'attribute_id' => $attribute_key ) ) ); $item_response = $this->prepare_response_for_collection( $item_response ); $response[] = $item_response; } return $response; }