WC_REST_Product_Attributes_V1_Controller::prepare_item_for_response() public WC 1.0
Prepare a single product attribute output for response.
{} It's a method of the class: WC_REST_Product_Attributes_V1_Controller{}
Hooks from the method
Return
WP_REST_Response. $response
Usage
$WC_REST_Product_Attributes_V1_Controller = new WC_REST_Product_Attributes_V1_Controller(); $WC_REST_Product_Attributes_V1_Controller->prepare_item_for_response( $item, $request );
- $item(obj) (required)
- Term object.
- $request(WP_REST_Request) (required)
- -
Code of WC_REST_Product_Attributes_V1_Controller::prepare_item_for_response() WC REST Product Attributes V1 Controller::prepare item for response WC 5.0.0
public function prepare_item_for_response( $item, $request ) {
$data = array(
'id' => (int) $item->attribute_id,
'name' => $item->attribute_label,
'slug' => wc_attribute_taxonomy_name( $item->attribute_name ),
'type' => $item->attribute_type,
'order_by' => $item->attribute_orderby,
'has_archives' => (bool) $item->attribute_public,
);
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
$response = rest_ensure_response( $data );
$response->add_links( $this->prepare_links( $item ) );
/**
* Filter a attribute item returned from the API.
*
* Allows modification of the product attribute data right before it is returned.
*
* @param WP_REST_Response $response The response object.
* @param object $item The original attribute object.
* @param WP_REST_Request $request Request used to generate the response.
*/
return apply_filters( 'woocommerce_rest_prepare_product_attribute', $response, $item, $request );
}