@@ -33,42 +33,41 @@ $woocommerce = new Client(
33
33
'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
34
34
'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
35
35
[
36
- 'wp_api' => true,
37
36
'version' => 'wc/v3',
38
37
]
39
38
);
40
39
```
41
40
41
+ ## Client class
42
+
43
+ ``` php
44
+ $woocommerce = new Client($url, $consumer_key, $consumer_secret, $options)
45
+ ```
46
+
42
47
### Options
43
48
44
- | Option | Type | Required | Description |
45
- | ----------------- | -------- | -------- | ------------------------------------------ |
49
+ | Option | Type | Required | Description |
50
+ | ------------------- | ---------- | ---------- | -------------------------------------------- |
46
51
| ` url ` | ` string ` | yes | Your Store URL, example: http://woo.dev/ |
47
52
| ` consumer_key ` | ` string ` | yes | Your API consumer key |
48
53
| ` consumer_secret ` | ` string ` | yes | Your API consumer secret |
49
54
| ` options ` | ` array ` | no | Extra arguments (see client options table) |
50
55
51
56
#### Client options
52
57
53
- | Option | Type | Required | Description |
58
+ | Option | Type | Required | Description |
54
59
| ---------------------| ----------| ----------| ------------------------------------------------------------------------------------------------------------------------|
55
- | ` wp_api ` | ` bool ` | no | Allow make requests to the new WP REST API integration (WooCommerce 2.6 or later) |
56
- | ` wp_api_prefix ` | ` string ` | no | Custom WP REST API URL prefix, used to support custom prefixes created with the ` rest_url_prefix ` filter |
57
- | ` version ` | ` string ` | no | API version, default is ` v3 ` |
60
+ | ` version ` | ` string ` | no | API version, default is ` wc/v3 ` |
58
61
| ` timeout ` | ` int ` | no | Request timeout, default is ` 15 ` |
59
- | ` follow_redirects ` | ` bool ` | no | Allow the API call to follow redirects |
60
62
| ` verify_ssl ` | ` bool ` | no | Verify SSL when connect, use this option as ` false ` when need to test with self-signed certificates, default is ` true ` |
63
+ | ` follow_redirects ` | ` bool ` | no | Allow the API call to follow redirects |
61
64
| ` query_string_auth ` | ` bool ` | no | Force Basic Authentication as query string when ` true ` and using under HTTPS, default is ` false ` |
62
65
| ` oauth_timestamp ` | ` string ` | no | Custom oAuth timestamp, default is ` time() ` |
63
66
| ` user_agent ` | ` string ` | no | Custom user-agent, default is ` WooCommerce API Client-PHP ` |
67
+ | ` wp_api_prefix ` | ` string ` | no | Custom WP REST API URL prefix, used to support custom prefixes created with the ` rest_url_prefix ` filter |
68
+ | ` wp_api ` | ` bool ` | no | Set to ` false ` in order to use the legacy WooCommerce REST API (deprecated and not recommended) |
64
69
65
- ## Methods
66
-
67
- | Params | Type | Description |
68
- | ------------ | -------- | ------------------------------------------------------------ |
69
- | ` endpoint ` | ` string ` | WooCommerce API endpoint, example: ` customers ` or ` order/12 ` |
70
- | ` data ` | ` array ` | Only for POST and PUT, data that will be converted to JSON |
71
- | ` parameters ` | ` array ` | Only for GET and DELETE, request query string |
70
+ ## Client methods
72
71
73
72
### GET
74
73
@@ -100,18 +99,26 @@ $woocommerce->delete($endpoint, $parameters = [])
100
99
$woocommerce->options($endpoint)
101
100
```
102
101
102
+ #### Arguments
103
+
104
+ | Params | Type | Description |
105
+ | --------------| ----------| --------------------------------------------------------------|
106
+ | ` endpoint ` | ` string ` | WooCommerce API endpoint, example: ` customers ` or ` order/12 ` |
107
+ | ` data ` | ` array ` | Only for POST and PUT, data that will be converted to JSON |
108
+ | ` parameters ` | ` array ` | Only for GET and DELETE, request query string |
109
+
103
110
#### Response
104
111
105
112
All methods will return arrays on success or throwing ` HttpClientException ` errors on failure.
106
113
107
-
108
114
``` php
109
115
use Automattic\WooCommerce\HttpClient\HttpClientException;
110
116
111
117
try {
112
118
// Array of response results.
113
119
$results = $woocommerce->get('customers');
114
120
// Example: ['customers' => [[ 'id' => 8, 'created_at' => '2015-05-06T17:43:51Z', 'email' => ...
121
+ echo '<pre ><code >' . print_r( $results, true ) . '</code ><pre >'; // JSON output.
115
122
116
123
// Last request data.
117
124
$lastRequest = $woocommerce->http->getRequest();
@@ -136,6 +143,7 @@ try {
136
143
137
144
## Release History
138
145
146
+ - 2019-01-16 - 3.0.0 - Legacy API turned off by default, and improved JSON error handler.
139
147
- 2018-03-29 - 2.0.1 - Fixed fatal errors on ` lookForErrors ` .
140
148
- 2018-01-12 - 2.0.0 - Responses changes from arrays to ` stdClass ` objects. Added ` follow_redirects ` option.
141
149
- 2017-06-06 - 1.3.0 - Remove BOM before decoding and added support for multi-dimensional arrays for oAuth1.0a.
0 commit comments