WordPress at Your Fingertips
function is not described

WC_API::get_endpoint_data() public WC 3.7.0

Get data from a WooCommerce API endpoint.

{} It's a 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 passwith request.
Default: array()

Changelog

Since 3.7.0 Introduced.

Code of WC_API::get_endpoint_data() WC 5.9.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 );
}