I am using woo-commerce REST API for getting shipping methods Woocommerce REST API
I have called $woocommerce->get('shipping/zones/3/methods')
but not receiving any output it's given errorUncaught Automattic\\WooCommerce\\HttpClient\\HttpClientException following is my code
<?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;
If someone know about Woocommerce REST API then please let me know how could i get all shipping methods with it's cost (also zone vise)
The error means that your code produced a "HttpClientException" exception and you did not handled it. To catch an exception you can use an try/catch bloc.
With your code it could be look like this:
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.