WC_REST_Shipping_Zone_Methods_V2_Controller::prepare_item_for_response()publicWC 1.0

Prepare the Shipping Zone Method for the REST response.

Method of the class: WC_REST_Shipping_Zone_Methods_V2_Controller{}

No Hooks.

Return

WP_REST_Response. $response

Usage

$WC_REST_Shipping_Zone_Methods_V2_Controller = new WC_REST_Shipping_Zone_Methods_V2_Controller();
$WC_REST_Shipping_Zone_Methods_V2_Controller->prepare_item_for_response( $item, $request );
$item(array) (required)
Shipping Zone Method.
$request(WP_REST_Request) (required)
Request object.

WC_REST_Shipping_Zone_Methods_V2_Controller::prepare_item_for_response() code WC 8.7.0

public function prepare_item_for_response( $item, $request ) {
	$method = array(
		'id'                 => $item->instance_id,
		'instance_id'        => $item->instance_id,
		'title'              => $item->instance_settings['title'],
		'order'              => $item->method_order,
		'enabled'            => ( 'yes' === $item->enabled ),
		'method_id'          => $item->id,
		'method_title'       => $item->method_title,
		'method_description' => $item->method_description,
		'settings'           => $this->get_settings( $item ),
	);

	$context = empty( $request['context'] ) ? 'view' : $request['context'];
	$data    = $this->add_additional_fields_to_object( $method, $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( $request['zone_id'], $item->instance_id ) );

	$response = $this->prepare_response_for_collection( $response );

	return $response;
}