A PHP wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library.
Feedback and bug reports are appreciated.
NOTE: This is a fork of kloon's repository adapted to work with v3 WooCommerce API and include the bulk product update/creation
PHP 5.2.x cURL WooCommerce 2.2 at least on the store
Generate API credentials (Consumer Key & Consumer Secret) under WP Admin > Your Profile.
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() );
}
}
-
debug
(defaultfalse
) - set totrue
to add request/response information to the returned data. This is particularly useful for troubleshooting errors. -
return_as_array
(defaultfalse
) - all methods return data as astdClass
by default, but you can set this option totrue
to return data as an associative array instead. -
validate_url
(defaultfalse
) - set this totrue
to verify that the URL provided has a valid, parseable WC API index, and optionally force SSL when supported. -
timeout
(default30
) - set this to control the HTTP timeout for requests. -
ssl_verify
(defaulttrue
) - set this tofalse
if you don't want to perform SSL peer verification for every request.
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.
$client->index->get()
- get the API index
$client->orders->get()
- get a list of orders$client->orders->get( null, array( 'status' => 'completed' ) )
- get a list of completed orders$client->orders->get( $order_id )
- get a single order
$client->bulk->send( $products_array )
- bulk edit/create maximum 100 products each call. Be sure to put the product ID in the array if you want to update that product. Missing ID will create a new product
Copyright (c) 2013-2014 - Gerhard Potgieter, Max Rice and other contributors
Released under the GPL3 license