WC_REST_Customers_V2_Controller::prepare_item_for_response()
Prepare a single customer output for response.
Method of the class: WC_REST_Customers_V2_Controller{}
Hooks from the method
Return
WP_REST_Response
. $response Response data.
Usage
$WC_REST_Customers_V2_Controller = new WC_REST_Customers_V2_Controller(); $WC_REST_Customers_V2_Controller->prepare_item_for_response( $user_data, $request );
- $user_data(WP_User) (required)
- User object.
- $request(WP_REST_Request) (required)
- Request object.
WC_REST_Customers_V2_Controller::prepare_item_for_response() WC REST Customers V2 Controller::prepare item for response code WC 9.3.3
public function prepare_item_for_response( $user_data, $request ) { $customer = new WC_Customer( $user_data->ID ); $data = $this->get_formatted_item_data( $customer ); $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( $user_data ) ); //phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment /** * Filter customer data returned from the REST API. * * @param WP_REST_Response $response The response object. * @param WP_User $user_data User object used to create response. * @param WP_REST_Request $request Request object. */ return apply_filters( 'woocommerce_rest_prepare_customer', $response, $user_data, $request ); //phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment }