• Stars
    star
    521
  • Rank 84,952 (Top 2 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 10 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

WooCommerce REST API PHP Library

WooCommerce API - PHP Client

A PHP wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API securely using this library. If using a HTTPS connection this library uses BasicAuth, else it uses Oauth to provide a secure connection to WooCommerce.

CI status Scrutinizer Code Quality PHP version

Installation

composer require automattic/woocommerce

Getting started

Generate API credentials (Consumer Key & Consumer Secret) following this instructions http://docs.woocommerce.com/document/woocommerce-rest-api/ .

Check out the WooCommerce API endpoints and data that can be manipulated in https://woocommerce.github.io/woocommerce-rest-api-docs/.

Setup

Setup for the new WP REST API integration (WooCommerce 2.6 or later):

require __DIR__ . '/vendor/autoload.php';

use Automattic\WooCommerce\Client;

$woocommerce = new Client(
  'http://example.com',
  'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  [
    'version' => 'wc/v3',
  ]
);

Client class

$woocommerce = new Client($url, $consumer_key, $consumer_secret, $options);

Options

Option Type Required Description
url string yes Your Store URL, example: http://woo.dev/
consumer_key string yes Your API consumer key
consumer_secret string yes Your API consumer secret
options array no Extra arguments (see client options table)

Client options

Option Type Required Description
version string no API version, default is wc/v3
timeout int no Request timeout, default is 15
verify_ssl bool no Verify SSL when connect, use this option as false when need to test with self-signed certificates, default is true
follow_redirects bool no Allow the API call to follow redirects
query_string_auth bool no Force Basic Authentication as query string when true and using under HTTPS, default is false
oauth_timestamp string no Custom oAuth timestamp, default is time()
oauth_only bool no Only use oauth for requests, it will disable Basic Auth, default is false
user_agent string no Custom user-agent, default is WooCommerce API Client-PHP
wp_api_prefix string no Custom WP REST API URL prefix, used to support custom prefixes created with the rest_url_prefix filter
wp_api bool no Set to false in order to use the legacy WooCommerce REST API (deprecated and not recommended)
method_override_query bool no If true will mask all non-GET/POST methods by using POST method with added query parameter ?_method=METHOD into URL
method_override_header bool no If true will mask all non-GET/POST methods (PUT/DELETE/etc.) by using POST method with added X-HTTP-Method-Override: METHOD HTTP header into request

Client methods

GET

$woocommerce->get($endpoint, $parameters = []);

POST

$woocommerce->post($endpoint, $data);

PUT

$woocommerce->put($endpoint, $data);

DELETE

$woocommerce->delete($endpoint, $parameters = []);

OPTIONS

$woocommerce->options($endpoint);

Arguments

Params Type Description
endpoint string WooCommerce API endpoint, example: customers or order/12
data array Only for POST and PUT, data that will be converted to JSON
parameters array Only for GET and DELETE, request query string

Response

All methods will return arrays on success or throwing HttpClientException errors on failure.

use Automattic\WooCommerce\HttpClient\HttpClientException;

try {
  // Array of response results.
  $results = $woocommerce->get('customers');
  // Example: ['customers' => [[ 'id' => 8, 'created_at' => '2015-05-06T17:43:51Z', 'email' => ...
  echo '<pre><code>' . print_r($results, true) . '</code><pre>'; // JSON output.

  // Last request data.
  $lastRequest = $woocommerce->http->getRequest();
  echo '<pre><code>' . print_r($lastRequest->getUrl(), true) . '</code><pre>'; // Requested URL (string).
  echo '<pre><code>' .
    print_r($lastRequest->getMethod(), true) .
    '</code><pre>'; // Request method (string).
  echo '<pre><code>' .
    print_r($lastRequest->getParameters(), true) .
    '</code><pre>'; // Request parameters (array).
  echo '<pre><code>' .
    print_r($lastRequest->getHeaders(), true) .
    '</code><pre>'; // Request headers (array).
  echo '<pre><code>' . print_r($lastRequest->getBody(), true) . '</code><pre>'; // Request body (JSON).

  // Last response data.
  $lastResponse = $woocommerce->http->getResponse();
  echo '<pre><code>' . print_r($lastResponse->getCode(), true) . '</code><pre>'; // Response code (int).
  echo '<pre><code>' .
    print_r($lastResponse->getHeaders(), true) .
    '</code><pre>'; // Response headers (array).
  echo '<pre><code>' . print_r($lastResponse->getBody(), true) . '</code><pre>'; // Response body (JSON).
} catch (HttpClientException $e) {
  echo '<pre><code>' . print_r($e->getMessage(), true) . '</code><pre>'; // Error message.
  echo '<pre><code>' . print_r($e->getRequest(), true) . '</code><pre>'; // Last request data.
  echo '<pre><code>' . print_r($e->getResponse(), true) . '</code><pre>'; // Last response data.
}

Release History

  • 2022-03-18 - 3.1.0 - Added new options to support _method and X-HTTP-Method-Override from WP, supports 7+, dropped support to PHP 5.
  • 2019-01-16 - 3.0.0 - Legacy API turned off by default, and improved JSON error handler.
  • 2018-03-29 - 2.0.1 - Fixed fatal errors on lookForErrors.
  • 2018-01-12 - 2.0.0 - Responses changes from arrays to stdClass objects. Added follow_redirects option.
  • 2017-06-06 - 1.3.0 - Remove BOM before decoding and added support for multi-dimensional arrays for oAuth1.0a.
  • 2017-03-15 - 1.2.0 - Added user_agent option.
  • 2016-12-14 - 1.1.4 - Fixed WordPress 4.7 compatibility.
  • 2016-10-26 - 1.1.3 - Allow set oauth_timestamp and improved how is handled the response headers.
  • 2016-09-30 - 1.1.2 - Added wp_api_prefix option to allow custom WP REST API URL prefix.
  • 2016-05-10 - 1.1.1 - Fixed oAuth and error handler for WP REST API.
  • 2016-05-09 - 1.1.0 - Added support for WP REST API, added method Automattic\WooCommerce\Client::options and fixed multiple headers responses.
  • 2016-01-25 - 1.0.2 - Fixed an error when getting data containing non-latin characters.
  • 2016-01-21 - 1.0.1 - Sort all oAuth parameters before build request URLs.
  • 2016-01-11 - 1.0.0 - Stable release.

More Repositories

1

woocommerce

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
PHP
9,371
star
2

FlexSlider

An awesome, fully responsive jQuery slider plugin
JavaScript
4,918
star
3

storefront

Official theme for WooCommerce
PHP
939
star
4

action-scheduler

A scalable, traceable job queue for background processing large queues of tasks in WordPress. Specifically designed for distribution in WordPress plugins (and themes) - no server access required.
PHP
631
star
5

woocommerce-blocks

(Deprecated) This plugin has been merged into woocommerce/woocommerce
TypeScript
404
star
6

woocommerce-admin

(Deprecated) This plugin has been merged to woocommerce/woocommerce
PHP
361
star
7

theme-customisations

PHP
313
star
8

wc-smooth-generator

Smooth product, customer and order generation for WooCommerce
PHP
311
star
9

woocommerce-ios

WooCommerce iOS app
Swift
301
star
10

woocommerce-rest-api-js-lib

New JavaScript library for WooCommerce REST API
JavaScript
285
star
11

woocommerce-android

WooCommerce Android app
Kotlin
277
star
12

woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
PHP
234
star
13

wc-api-python

A Python wrapper for the WooCommerce API.
Python
211
star
14

facebook-for-woocommerce

A first-party extension plugin built for WooCommerce. Development is managed by Ventures.
PHP
211
star
15

woocommerce-product-tables-feature-plugin

Implements new data-stores and moves product data into custom tables, with a new, normalised data structure.
PHP
192
star
16

woocommerce-google-analytics-integration

WordPress plugin: Provides the integration between WooCommerce and Google Analytics.
PHP
152
star
17

wc-api-node

This client is obsolete and will no longer receive updates, a new JavaScript library is available under the name of @woocommerce/woocommerce-rest-api
JavaScript
144
star
18

woocommerce-subscriptions-importer-exporter

Import your subscribers to WooCommerce from a CSV. Or export your subscription data from WooCommerce to CSV.
PHP
138
star
19

woocommerce-rest-api-docs

WooCommerce REST API Documentation
JavaScript
130
star
20

woocommerce-accommodation-bookings

An accommodations add-on for the WooCommerce Bookings extension.
PHP
91
star
21

woocommerce-language-packs

This repo is deprecated - translation should be done on https://translate.wordpress.org/projects/wp-plugins/woocommerce/
JavaScript
83
star
22

woocommerce-rest-api

This is the WooCommerce core REST API Package. It runs standalone as a feature plugin too.
PHP
70
star
23

wc-api-ruby

A Ruby wrapper for the WooCommerce API.
Ruby
69
star
24

woocommerce-gateway-dummy

A Dummy Payments gateway for your WooCommerce website.
PHP
66
star
25

woocommerce-paypal-payments

PHP
62
star
26

woocommerce-subscriptions-custom-price-string

Customize the price displayed to your customers for subscription products (or non-subscription product).
PHP
61
star
27

woocommerce-gateway-paypal-express-checkout

PHP
59
star
28

testimonials

Hi, I'm your testimonials management plugin for WordPress. Show off what your customers or website users are saying about your business and how great they say you are, using our shortcode, widget or template tag.
PHP
59
star
29

action-scheduler-high-volume

Increase Action Scheduler time limit, queue size and concurrency to process large queues of actions more quickly on high volume websites with more server resources.
PHP
56
star
30

features

Hi, I'm your feature showcase plugin for WordPress. Show off what features your company, product or service offers using our shortcode, widget or template tag.
PHP
53
star
31

woosidebars

Replace registered sidebars in your WordPress themes using different conditions such as a specific page, a category or even an individual blog post.
PHP
50
star
32

action-scheduler-disable-default-runner

Disable Action Scheduler's default queue runner, by removing it from the 'action_scheduler_run_queue' hook.
PHP
49
star
33

woocommerce-sniffs

Collection of PHP_CodeSniffer sniffs for WooCommerce
PHP
48
star
34

google-listings-and-ads

Sync your store with Google to list products for free, run paid ads, and track performance straight from your store dashboard.
PHP
47
star
35

houston

A child theme for the popular P2 WordPress theme, used on WooThemes internal P2 properties.
CSS
47
star
36

wc-api-dev

This is a repository is obsolete, WooCommerce REST API is now located in https://github.com/woocommerce/woocommerce-rest-api
PHP
44
star
37

woocommerce-gateway-payfast

South African payment gateway supporting subscriptions, deposits & pre-orders
PHP
41
star
38

projects

PHP
40
star
39

grant-download-permissions-for-past-woocommerce-orders

This plugin grants downloads permissions like WooCommerce 2.6.x, granting permissions for new files added to a downloadable product. Note that this plugin performs heavy database queries and does not scale. For this reason it has been removed from WooCommerce core.
PHP
39
star
40

woocommerce-subscriptions-cancel-subscription-confirmation

Require your subscribers to confirm just-one-more-time before cancelling their subscription.
PHP
37
star
41

our-team

Hi, I'm your team profile management plugin for WordPress. Show off what your team members using our shortcode, widget or template tag.
PHP
35
star
42

automatewoo-subscriptions

⚠️ DO NOT USE - AutomateWoo's Subscription add-on was merged into AutomateWoo 5.4. Advanced actions for automating a subscription's lifecycle with AutomateWoo.
PHP
34
star
43

woocommerce-subscriptions-preserve-billing-schedule

By default, WooCommerce Subscriptions will calculate the next payment date for a subscription from the time of the last payment. This plugin changes that to preserve the original schedule and calculate the next payment date from the scheduled payment date, not the time the payment was actually processed.
PHP
34
star
44

bookings-helper

This extension is a WooCommerce Bookings helper which helps you to troubleshoot bookings setup easier by allowing you to quickly export/import product settings.
PHP
32
star
45

storechild

Child theme starter for Storefront
PHP
32
star
46

woocommerce-icons

HTML
32
star
47

sensei-certificates

Hi, I'm the Certificates extension for Sensei.
PHP
31
star
48

woocommerce-beta-tester

Run the beta versions of WooCommerce
PHP
29
star
49

woocommerce-subscriptions-resource

A library to track and prorate payments for a subscription using WooCommerce Subscriptions based on the status of an external resource.
PHP
26
star
50

woocommerce-custom-indexes

PHP
23
star
51

pinterest-for-woocommerce

A native Pinterest integration for WooCommerce. Development is managed by Ventures.
PHP
22
star
52

woocommerce-subscriptions-skip-pending-cancel

Subscriptions will skip Pending Cancellation and go directly to Cancelled status when Customer cancels their subscription.
PHP
21
star
53

woocommerce-gateway-amazon-pay

Amazon Pay Gateway
PHP
20
star
54

qit-cli

A Testing Platform for WordPress Plugins and Themes
PHP
19
star
55

homepage-control

Re-order or disable the components of your homepage in our newer WordPress themes.
PHP
19
star
56

woocommerce-colors

PHP
19
star
57

woocommerce-e2e-boilerplate

JavaScript
18
star
58

boutique

CSS
17
star
59

woocommerce-product-bundles-bulk-discounts

Bulk discounts and dynamic pricing rules for WooCommerce Product Bundles.
PHP
16
star
60

sensei-content-drip

A content drip extension for Sensei.
PHP
16
star
61

code-reference

WooCommerce Code Reference Generator
Twig
16
star
62

sensei-course-progress

A course progress widget for Sensei.
PHP
16
star
63

woocommerce-subscriptions-cancel-on-refund

Cancel a subscription when the most recent order is fully refunded. Both refunds on a parent or renewal order will trigger cancellation, as long as it is the most recent order.
PHP
16
star
64

action-scheduler-custom-tables

This plugin is no longer needed. The custom table code is now part of Action Scheduler version 3.0 and newer. If you're using the latest Action Scheduler, you have the most performant schema available.
PHP
14
star
65

action-scheduler-timeout-monitor

Gather additional information about scheduled actions which timeout.
PHP
14
star
66

subscribe-for-content

A WordPress plugin that allows you to hide content until a user subscribes to your MailChimp mailing list 😍
PHP
13
star
67

automations

Various GitHub Action automations to assist with repository project management.
JavaScript
13
star
68

storefront-product-sharing

PHP
13
star
69

woocommerce-subscriptions-recalculate-totals

In some cases, if the tax settings change after some subscriptions have been created, their totals need to be recalculated in order to include the proper taxes. This plugin recalculates all the subscriptions totals.
PHP
13
star
70

migrator-cli

An experimental WP-CLI based migration tool for moving Shopify stores to WooCommerce.
PHP
13
star
71

woocommerce-subscriptions-restrict-product

Restricts subscription products to a certain number of total active (unended) subscriptions on a site.
PHP
13
star
72

woocommerce-stellar

Accept payment for WooCommerce orders via Stellar (both the currency and the protocol).
JavaScript
12
star
73

woocommerce-order-tables-feature-plugin

Order tables for WooCommerce.
12
star
74

WooCommerce-Quantity-Increment

Adds back <= WooCommerce 2.2 quantity increment buttons
CSS
12
star
75

woocommerce-subscriptions-upstage

Disable Staging Mode for specific subscriptions, as defined in a WCS_UPSTAGED_SUBSCRIPTION_IDS constant.
PHP
12
star
76

woocommerce-free-shipping-progress-bar-block

An inner block for the Cart that indicates how much more is needed to get free shipping.
JavaScript
12
star
77

action-scheduler-admin

Action Scheduler screen for the WooCommerce Admin interface
JavaScript
12
star
78

icons-for-features

Optionally display an icon, instead of a featured image, for your Features by WooThemes features.
CSS
11
star
79

woocommerce-shortcodes

JavaScript
11
star
80

standard-child-theme-kit

This is a "getting started" child theme kit for Standard by 8BIT.
PHP
11
star
81

woocommerce-subscriptions-renewal-logger

Determine why automatic subscription renewal payments aren't being processed despite using an automatic gateway.
PHP
11
star
82

woocommerce-composite-products-conditional-images

Composite Products mini-extension that allows you to conditionally overlay additional images over the main Composite Product image.
PHP
11
star
83

woocommerce-square

Square POS and Payments Integration
PHP
11
star
84

deli

CSS
10
star
85

archives

Hi, we're a collection of archive functions for WordPress. Use us to display archives of your content in "Timeline" or "Sitemap" format, using either a shortcode, action or template tag.
PHP
10
star
86

wceu23-shipping-workshop-final

PHP
10
star
87

subscribe-and-connect

Hi, I'm here to help your visitors subscribe to your content, as well as share it across various social networks.
PHP
10
star
88

woocommerce-git-hooks

Collection of WooCommerce core git hooks.
PHP
10
star
89

woocommerce-bookings-generator

A small helper plugin for WooCommerce Bookings to generate a large number of Bookings on a test store, to measure how WooCommerce Bookings performs under high load.
PHP
10
star
90

sensei-course-participants

This extension has been retired and is no longer being actively maintained.
PHP
9
star
91

storefront-extension-boilerplate

PHP
9
star
92

wc-php-session-handler

Replaces the core WooCommerce session handler with one which uses php sessions.
PHP
9
star
93

woocommerce-legacy-rest-api

The legacy WooCommerce REST API, which used to be part of WooCommerce itself but is removed as of WooCommerce 9.0.
PHP
9
star
94

woocommerce-subscriptions-cancel-after-retry

Cancel a subscription after all failed payment retry attempts have failed.
PHP
9
star
95

woocommerce-subscriptions-backstage

Disable WooCommerce Subscriptions' Staging Mode completely. Caveat emptor.
PHP
9
star
96

woocommerce-subscriptions-disable-paypal

Using WooCommerce Subscriptions? Want to disable PayPal for subscription purchases, but still offer it for buying one-off products? Install and activate this plugin.
PHP
9
star
97

woocommerce-product-type-column

WooCommerce Product Type Column
PHP
8
star
98

woocommerce-jigoshop-converter

Convert existing shop data from Jigoshop to WooCommerce.
PHP
8
star
99

woocommerce-example-package

Example package for a WooCommerce feature plugin that can also be included in core.
Shell
8
star
100

woocommerce-core-to-wordpress-org

Plugin deploy script used for Deploying WooCommerce amongst other things.
Shell
8
star