kloon / WooCommerce-REST-API-Client-Library

A PHP wrapper for the WooCommerce REST API
GNU General Public License v3.0
356 stars 175 forks source link

WooCommerce REST API PHP Client Library

About

A PHP wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library.

Feedback and bug reports are appreciated.

Requirements

PHP 5.2.x cURL WooCommerce 2.2 at least on the store

Getting started

Generate API credentials (Consumer Key & Consumer Secret) under WP Admin > Your Profile.

Setup the library

require_once( 'lib/woocommerce-api.php' );

$options = array(
    'ssl_verify'      => false,
);

try {

    $client = new WC_API_Client( 'http://your-store-url.com', $consumer_key, $consumer_secret, $options );

} catch ( WC_API_Client_Exception $e ) {

    echo $e->getMessage() . PHP_EOL;
    echo $e->getCode() . PHP_EOL;

    if ( $e instanceof WC_API_Client_HTTP_Exception ) {

        print_r( $e->get_request() );
        print_r( $e->get_response() );
    }
}

Options

Error handling

Exceptions are thrown when errors are encountered, most will be instances of WC_API_Client_HTTP_Exception which has two additional methods, get_request() and get_response() -- these return the request and response objects to help with debugging.

Methods

Index

Orders

Credit

Copyright (c) 2013-2014 - Gerhard Potgieter, Max Rice and other contributors

License

Released under the GPL3 license