Automattic\WooCommerce\Internal\RestApi\Routes\V4\ShippingZoneMethod
Controller::get_route_error_by_code
Get route error by code, including custom shipping method errors.
Method of the class: Controller{}
No Hooks.
Returns
WP_Error.
Usage
// protected - for code of main (parent) or child class $result = $this->get_route_error_by_code( $error_code ): WP_Error;
- $error_code(string) (required)
- Error code.
Controller::get_route_error_by_code() Controller::get route error by code code WC 10.4.3
protected function get_route_error_by_code( string $error_code ): WP_Error {
$custom_errors = array(
self::INVALID_ZONE_ID => array(
'message' => __( 'Invalid shipping zone ID.', 'woocommerce' ),
'status' => WP_Http::NOT_FOUND,
),
self::INVALID_METHOD_TYPE => array(
'message' => __( 'Invalid shipping method type.', 'woocommerce' ),
'status' => WP_Http::BAD_REQUEST,
),
self::ZONE_MISMATCH => array(
'message' => __( 'Shipping method does not belong to the specified zone.', 'woocommerce' ),
'status' => WP_Http::BAD_REQUEST,
),
);
if ( isset( $custom_errors[ $error_code ] ) ) {
return $this->get_route_error_response(
$this->get_error_prefix() . $error_code,
$custom_errors[ $error_code ]['message'],
$custom_errors[ $error_code ]['status']
);
}
return parent::get_route_error_by_code( $error_code );
}