WC_REST_Customer_Downloads_V1_Controller::prepare_item_for_response()publicWC 1.0

Prepare a single download output for response.

Method of the class: WC_REST_Customer_Downloads_V1_Controller{}

Return

WP_REST_Response. $response Response data.

Usage

$WC_REST_Customer_Downloads_V1_Controller = new WC_REST_Customer_Downloads_V1_Controller();
$WC_REST_Customer_Downloads_V1_Controller->prepare_item_for_response( $download, $request );
$download(stdObject) (required)
Download object.
$request(WP_REST_Request) (required)
Request object.

WC_REST_Customer_Downloads_V1_Controller::prepare_item_for_response() code WC 8.6.1

public function prepare_item_for_response( $download, $request ) {
	$data = (array) $download;
	$data['access_expires']      = $data['access_expires'] ? wc_rest_prepare_date_response( $data['access_expires'] ) : 'never';
	$data['downloads_remaining'] = '' === $data['downloads_remaining'] ? 'unlimited' : $data['downloads_remaining'];

	// Remove "product_name" since it's new in 3.0.
	unset( $data['product_name'] );

	$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
	$data    = $this->add_additional_fields_to_object( $data, $request );
	$data    = $this->filter_response_by_context( $data, $context );

	// Wrap the data in a response object.
	$response = rest_ensure_response( $data );

	$response->add_links( $this->prepare_links( $download, $request ) );

	/**
	 * Filter customer download data returned from the REST API.
	 *
	 * @param WP_REST_Response $response  The response object.
	 * @param stdObject        $download  Download object used to create response.
	 * @param WP_REST_Request  $request   Request object.
	 */
	return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request );
}