我正在使用woo-commerce REST API获取运输方式Woocommerce REST API
我已经致电$woocommerce->get('shipping/zones/3/methods')
,但没有收到任何给出的输出 errorUncaught Automattic \ WooCommerce \ HttpClient \ HttpClientException ,以下是我的代码
<?php
include('../wp-load.php');
require_once( 'woo-lib/autoload.php' );
require_once( 'auth_keys.php' );
use Automattic\WooCommerce\Client;
if(isset($keys) && !empty($keys)){
$woocommerce = new Client(
$keys['siteurl'],
$keys['consumer_key'],
$keys['consumer_secret'],
[
'wp_api' => true,
'version' => 'wc/v2',
]
);
}
print_r($woocommerce->get('shipping/zones/3/methods'));
die;
如果有人了解Woocommerce REST API,请告诉我如何获得所有费用的运输方式(还有区域虎钳)
答案 0 :(得分:0)
该错误表示您的代码产生了“ HttpClientException”异常,而您没有对其进行处理。要捕获异常,可以使用try / catch bloc。
使用您的代码,可能看起来像这样:
include('../wp-load.php');
require_once( 'woo-lib/autoload.php' );
require_once( 'auth_keys.php' );
use Automattic\WooCommerce\HttpClient\HttpClientException;
use Automattic\WooCommerce\Client;
if(isset($keys) && !empty($keys))
{
$woocommerce = new Client(
$keys['siteurl'],
$keys['consumer_key'],
$keys['consumer_secret'],
[
'wp_api' => true,
'version' => 'wc/v2',
]
);
try {
$result = $woocommerce->get('shipping/zones/3/methods');
} catch ( HttpClientException $e ) {
// print out the exception message => maybe it tells you the error
print_r($e->getMessage() );
}
print_r($result);
}