Reputation: 166
I am new to Woocomerce Rest API. I am trying to fetch all products from woocomerce in my new web application in php. But something went wrong from fetching that data. Here is my basic code :-
<?php
require_once ('vendor\autoload.php');
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'https://www.cotncurls.com',
'*************************',
'*************************',
[
'wp_api' => true,
'version' => 'wc/v3'
]
);
print_r($woocommerce->get('products'));
?>
But its showing me an error
Fatal error: Uncaught Error: Class 'Automattic\WooCommerce\Client' not found in ....
How to resolve this ?
Upvotes: 0
Views: 5219
Reputation: 166
Error will remain same until we do not use exception class..
<?php
require_once ('..\vendor\autoload.php');
use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;
$woocommerce = new Client(
'https://www.cottncurls.com',
'ck_****************************************',
'cs_****************************************',
[
'wp_api' => true,
'version' => 'wc/v2',
// 'query_string_auth' => true
]
);
print_r($woocommerce->get('products')); ?>
Here is the edited code.
Upvotes: 1
Reputation: 19
Here in this case I see you are directly requiring the file from URL , i suggest you to download the library from github or run through composer
composer require automattic/woocommerce
Upvotes: 0