WC_REST_Product_Attributes_V1_Controller::prepare_item_for_response()publicWC 1.0

Prepare a single product attribute output for response.

Метод класса: WC_REST_Product_Attributes_V1_Controller{}

Хуки из метода

Возвращает

WP_REST_Response.

Использование

$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) (обязательный)
Term object.
$request(WP_REST_Request) (обязательный)
The request to process.

Код WC_REST_Product_Attributes_V1_Controller::prepare_item_for_response() WC 8.7.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 );
}