Coder Social home page Coder Social logo

ryptoc / woocommerce-rest-api-client-library Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kloon/woocommerce-rest-api-client-library

0.0 2.0 0.0 535 KB

A PHP wrapper for the WooCommerce REST API

License: GNU General Public License v3.0

PHP 100.00%

woocommerce-rest-api-client-library's Introduction

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

  • debug (default false) - set to true to add request/response information to the returned data. This is particularly useful for troubleshooting errors.

  • return_as_array (default false) - all methods return data as a stdClass by default, but you can set this option to true to return data as an associative array instead.

  • validate_url (default false) - set this to true to verify that the URL provided has a valid, parseable WC API index, and optionally force SSL when supported.

  • timeout (default 30) - set this to control the HTTP timeout for requests.

  • ssl_verify (default true) - set this to false if you don't want to perform SSL peer verification for every request.

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

  • $client->index->get() - get the API index

Orders

  • $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

Credit

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

License

Released under the GPL3 license

woocommerce-rest-api-client-library's People

Contributors

maxrice avatar kloon avatar judgej avatar tillz avatar garypegeot-wic avatar claudiosanches avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.