WooCommerce REST API PHP 库
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.
composer require automattic/woocommerceGenerate API credentials (Consumer Key & Consumer Secret) following this instructions .
Check out the WooCommerce API endpoints and data that can be manipulated in .
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',
]
);$woocommerce = new Client($url, $consumer_key, $consumer_secret, $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) |
| 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 |
$woocommerce->get($endpoint, $parameters = []);$woocommerce->post($endpoint, $data);$woocommerce->put($endpoint, $data);$woocommerce->delete($endpoint, $parameters = []);$woocommerce->options($endpoint);| Params | Type | Description |
|---|---|---|
endpoint |
string |
WooCommerce API endpoint, example: customers or orders/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 |
All methods will return arrays on success or throwing HttpClientException errors on failure.
…arg_separator.output is configured as &, fixed empty errors array warning._method and X-HTTP-Method-Override from WP, supports 7+, dropped support to PHP 5.lookForErrors.stdClass objects. Added follow_redirects option.user_agent option.oauth_timestamp and improved how is handled the response headers.wp_api_prefix option to allow custom WP REST API URL prefix.Automattic\WooCommerce\Client::options and fixed multiple headers responses.暂无开放 Issues,或尚未同步最近议题。