问题
I am trying to get all orders that belongs to a specific customer using this endpoint in the WooCommerce API v2
http://woothemes.github.io/woocommerce-rest-api-docs/v2.html#view-customer-orders
using this library https://github.com/kloon/WooCommerce-REST-API-Client-Library
I have checked the website dashboard and there is pending orders
But I am always getting this response :-
[data] => Array ( ) [body] => [duration] => 1.36552 ) [response] => stdClass Object ( [body] => {"orders":[]} [code] => 200 [headers] => Array ( [Date] => Thu, 31 Mar 2016 07:37:35 GMT [Server] => Apache [X-Powered-By] => PHP/5.5.33 [Connection] => close [Transfer-Encoding] => chunked [Content-Type] => application/json; charset=UTF-8 ) ) ) )
Other endpoints in the API works fine this is my simple code
<?php
require_once( 'lib/woocommerce-api.php' );
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 30,
'ssl_verify' => false,
);
try {
$client = new WC_API_Client( 'http://localhost/store', $API_KEY, $API_SECRET, $options );
print_r($client->customers->get_orders($userId));
} catch ( WC_API_Client_Exception $e ) {
echo $e->getMessage() . PHP_EOL;
echo $e->getCode() . PHP_EOL;
if ( $e instanceof WC_API_Client_HTTP_Exception ) {
print_r( $e->get_request() );
print_r( $e->get_response() );
}
}
?>
来源:https://stackoverflow.com/questions/36327341/get-all-customer-orders-in-woocommerce-api