WC_API::get_endpoint_data()
Get data from a WooCommerce API endpoint.
Method of the class: WC_API{}
No Hooks.
Return
Array|\WP_Error
.
Usage
$WC_API = new WC_API(); $WC_API->get_endpoint_data( $endpoint, $params );
- $endpoint(string) (required)
- Endpoint.
- $params(array)
- Params to pass with request.
Default: array()
Changelog
Since 3.7.0 | Introduced. |
WC_API::get_endpoint_data() WC API::get endpoint data code WC 8.7.0
public function get_endpoint_data( $endpoint, $params = array() ) { if ( ! $this->is_rest_api_loaded() ) { return new WP_Error( 'rest_api_unavailable', __( 'The Rest API is unavailable.', 'woocommerce' ) ); } $request = new \WP_REST_Request( 'GET', $endpoint ); if ( $params ) { $request->set_query_params( $params ); } $response = rest_do_request( $request ); $server = rest_get_server(); $json = wp_json_encode( $server->response_to_data( $response, false ) ); return json_decode( $json, true ); }