Reputation: 31
I use woocommerce rest api for managing products and other things. Here are the step I follow in order to do it:
Step:1 Goto woocommerce settings->advance->
Legacy API
Step:2 Create REST API
Step:3 Code
$autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( is_readable( $autoloader ) ) {
require_once $autoloader;
}
use wordpress\CorePhp\WooCommerce\Client;
$woocommerce = new Client(
'http://localhost/wordpress',
'ck_44d1f5a2a193274e4dfba6ee7ec764cedd345000',
'cs_6be79b8bd5ec0dbb1828309db24ae338abce44b3',
[
'wp_api' => true,
'version' => 'wc/v2'
]
);
?>
Fatal error: Uncaught Error: Class 'wordpress\CorePhp\WooCommerce\Client' not found in C:\xampp\htdocs\wordpress\CorePhp\getproducts.php:9 Stack trace: #0 {main} thrown in C:\xampp\htdocs\wordpress\CorePhp\getproducts.php on line 9
Upvotes: 0
Views: 2487
Reputation: 31
i solve above issue there is issue with not install autoload in project folder that's why it give error here are the code which working proper :
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;
$woocommerce = new Client(
'http://localhost/wordpress',
'your consumer key',
'your secret key',
[
'wp_api' => true,
'version' => 'wc/v2'
]
);
/*var_dump($woocommerce);*/
?>
Upvotes: 1