尝试通过 WooCommerce Rest Api 创建订单时,我收到以下错误消息:错误:客户 ID 无效。
但是客户 ID 在请求中:
$data = '{
"order": {
"status": "processing",
"customer_id": 36,
"currency": "",
"billing_address": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "",
"phone": ""
},
"shipping_address": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"line_items": [
{
"id": null,
"quantity": 1,
"product_id": 271,
},
{
"id": null,
"quantity": 3,
"product_id": 273,
}
],
}
}';
完整代码
$client = new WC_API_Client( 'http://mywebsite.com', 'key', 'secret', $options );
$data = '{
"order": {
"status": "processing",
"customer_id": 36,
"currency": "",
"billing_address": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "",
"phone": ""
},
"shipping_address": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"line_items": [
{
"id": null,
"quantity": 1,
"product_id": 271,
},
{
"id": null,
"quantity": 3,
"product_id": 273,
}
],
}
}';
$client->orders->create($data);
} 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 ://github.com/woothemes/woocommerce/issues/8561
而且我可以确认没有任何 .htacess 文件有这个问题。甚至看起来像。