WC_REST_Taxes_V1_Controller::prepare_item_for_response
Prepare a single tax output for response.
Method of the class: WC_REST_Taxes_V1_Controller{}
Hooks from the method
Returns
WP_REST_Response. $response Response data.
Usage
$WC_REST_Taxes_V1_Controller = new WC_REST_Taxes_V1_Controller(); $WC_REST_Taxes_V1_Controller->prepare_item_for_response( $tax, $request );
- $tax(stdClass) (required)
- Tax object.
- $request(WP_REST_Request) (required)
- Request object.
WC_REST_Taxes_V1_Controller::prepare_item_for_response() WC REST Taxes V1 Controller::prepare item for response code WC 10.5.0
public function prepare_item_for_response( $tax, $request ) {
$id = (int) $tax->tax_rate_id;
$data = array(
'id' => $id,
'country' => $tax->tax_rate_country,
'state' => $tax->tax_rate_state,
'postcode' => '',
'city' => '',
'rate' => $tax->tax_rate,
'name' => $tax->tax_rate_name,
'priority' => (int) $tax->tax_rate_priority,
'compound' => (bool) $tax->tax_rate_compound,
'shipping' => (bool) $tax->tax_rate_shipping,
'order' => (int) $tax->tax_rate_order,
'class' => $tax->tax_rate_class ? $tax->tax_rate_class : 'standard',
);
$data = $this->add_tax_rate_locales( $data, $tax );
$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( $tax ) );
/**
* Filter tax object returned from the REST API.
*
* @param WP_REST_Response $response The response object.
* @param stdClass $tax Tax object used to create response.
* @param WP_REST_Request $request Request object.
*/
return apply_filters( 'woocommerce_rest_prepare_tax', $response, $tax, $request );
}