skip to Main Content

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 ('vendorautoload.php');

use AutomatticWooCommerceClient;

$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 'AutomatticWooCommerceClient' not found in .... 

How to resolve this ?

2

Answers


  1. Chosen as BEST ANSWER

    Error will remain same until we do not use exception class..

     <?php
    
    
    require_once ('..vendorautoload.php');
    
    use AutomatticWooCommerceClient;
    use AutomatticWooCommerceHttpClientHttpClientException;
    
    
    $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.


  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search