简体   繁体   中英

error in woocommerce REST Api integration

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

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);*/ 

?>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM