我试图在WooCommerce API v2中使用此端点获取属于特定客户的所有订单
http://woothemes.github.io/woocommerce-rest-api-docs/v2.html#view-customer-orders
使用此库https://github.com/kloon/WooCommerce-REST-API-Client-Library
我查看了网站信息中心,还有待处理的订单
但我总是得到这样的答复: -
[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 ) ) ) )
API中的其他端点工作正常,这是我的简单代码
<?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() );
}
}
?>