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).
Method of the class: ProductAttributes{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->format_custom_attribute_items_for_response( $custom_attributes );
- $custom_attributes(array) (required)
- - CustomAttributeTraits::get_custom_attributes().
ProductAttributes::format_custom_attribute_items_for_response() ProductAttributes::format custom attribute items for response code WC 10.4.3
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;
}