0

I'm new in WooCommerce REST API, I have worked with custom endpoints but I need some help/tutorial related to WooCommerce REST API. I have research about it but I didn't found any tutorial(s) for this.

I have got automattic/woocommerce and I have used below code in functions.php file:

require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
    'http://example.com', 
    'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 
    'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    [
        'wp_api' => true,
        'version' => 'wc/v2',
    ]
);

but when I use this on functions file my website shows 500 server error. I don't know am I doing some wrong/foolish thing on it.

Let me know what can I do for this issue

  • I don't see why you'd need to use the API in PHP if it's for the same website. Are you accessing a different website via the API? – Jacob Peattie Jan 9 at 6:38
  • I want to use it for mobile application development – Parth Shah Jan 9 at 6:38
  • You are way off track. automattic/woocommerce is a PHP package for communicating with another website's Woocommerce REST API from within a PHP application. WooCommerce already has the API built in. You create keys in WooCommerce > Settings > Advanced and then use those keys in your application to make requests to your site's API URL. – Jacob Peattie Jan 9 at 6:42
  • Oh! Thanks Jacob for clearing about it, now got it. so I got reference from woocommerce.github.io/woocommerce-rest-api-docs/… and I can't get anything on ** print_r($woocommerce->get('orders'));** so what to do for it? – Parth Shah Jan 9 at 6:47
  • Or it's good If you are suggest some better idea how to start work on woocommerce rest api. – Parth Shah Jan 9 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.