WC_REST_Shipping_Methods_V2_Controller::get_item
Get a single Shipping Method.
Method of the class: WC_REST_Shipping_Methods_V2_Controller{}
No Hooks.
Returns
WP_REST_Response|WP_Error.
Usage
$WC_REST_Shipping_Methods_V2_Controller = new WC_REST_Shipping_Methods_V2_Controller(); $WC_REST_Shipping_Methods_V2_Controller->get_item( $request );
- $request(WP_REST_Request) (required)
- Request data.
WC_REST_Shipping_Methods_V2_Controller::get_item() WC REST Shipping Methods V2 Controller::get item code WC 10.3.6
public function get_item( $request ) {
$wc_shipping = WC_Shipping::instance();
$methods = $wc_shipping->get_shipping_methods();
if ( empty( $methods[ $request['id'] ] ) ) {
return new WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
}
$method = $methods[ $request['id'] ];
$response = $this->prepare_item_for_response( $method, $request );
return rest_ensure_response( $response );
}