WC_REST_Taxes_V1_Controller::prepare_item_for_response()
Prepare a single tax output for response.
Метод класса: WC_REST_Taxes_V1_Controller{}
Хуки из метода
Возвращает
WP_REST_Response
. $response Response data.
Использование
$WC_REST_Taxes_V1_Controller = new WC_REST_Taxes_V1_Controller(); $WC_REST_Taxes_V1_Controller->prepare_item_for_response( $tax, $request );
- $tax(stdClass) (обязательный)
- Tax object.
- $request(WP_REST_Request) (обязательный)
- Request object.
Код WC_REST_Taxes_V1_Controller::prepare_item_for_response() WC REST Taxes V1 Controller::prepare item for response WC 9.6.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 ); }