Skip to content

Commit d247207

Browse files
committed
[#1] Update code example, fix doc issues, adjust css
1 parent b0a0fd1 commit d247207

File tree

12 files changed

+529
-420
lines changed

12 files changed

+529
-420
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,4 @@ Finally, after pushing changes and you are ready to deploy use the script:
3939

4040
```shell
4141
bash deploy.sh
42-
```
43-
44-
45-
42+
```

source/includes/_authentication.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Authentication
2+
3+
```php
4+
HTTP Basic Auth example:
5+
6+
<?php
7+
8+
require __DIR__ . '/vendor/autoload.php';
9+
10+
use Automattic\WooCommerce\Client;
11+
12+
$woocommerce = new Client(
13+
'https://example.com',
14+
'consumer_key',
15+
'consumer_secret',
16+
[
17+
'wp_api' => true,
18+
'version' => 'wc/v2'
19+
]
20+
);
21+
22+
?>
23+
24+
Occasionally, some servers may not parse the Authorization header correctly.
25+
26+
If you see a "Consumer key is missing" error when authenticating over SSL, likely you have a server issue.
27+
28+
In this case, you may provide the consumer key/secret as query string parameters instead.
29+
30+
Example for servers that not properly parse the Authorization header:
31+
32+
<?php
33+
34+
require __DIR__ . '/vendor/autoload.php';
35+
36+
use Automattic\WooCommerce\Client;
37+
38+
$woocommerce = new Client(
39+
'https://example.com',
40+
'consumer_key',
41+
'consumer_secret',
42+
[
43+
'wp_api' => true,
44+
'version' => 'wc/v2',
45+
// Force Basic Authentication as query string true and using under HTTPS
46+
'query_string_auth' => true
47+
]
48+
);
49+
50+
?>
51+
```
52+
53+
Since Memberships REST API is built on top of the WordPress REST API and requires WooCommerce to function, authorization for performing HTTP requests successfully is handled by WooCommerce and WordPress.
54+
55+
WooCommerce includes two ways to authenticate with the WP REST API. It is also possible to authenticate using any [WP REST API authentication plugin](http://v2.wp-api.org/guide/authentication/) or method.
56+
57+
Follow instructions from the [WooCommerce core REST API Authentication chapter](https://woocommerce.github.io/woocommerce-rest-api-docs/#authentication) for authentication guidelines.

source/includes/_discovery.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Discovery
2+
3+
## Available Routes
4+
5+
**`/memberships`**
6+
7+
The memberships root endpoint lists all routes, along with supported HTTP methods for each, made available by WooCommerce Memberships.
8+
9+
### HTTP REQUEST
10+
11+
`GET http://example.com/wp-json/wc/v2/memberships`

source/includes/_errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Error Code | Meaning
66
`401` | **Unauthorized** -- Authentication error.
77
`404` | **Not Found** -- The specified item could not be found.
88
`405` | **Method Not Allowed** -- The HTTP method you used isn't supported by the specified endpoint.
9-
`500` | **Internal Server Error** -- Something may be wrong with the site.
9+
`500` | **Internal Server Error** -- Something may be wrong with the site or the server.

source/includes/_introduction.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Introduction
2+
3+
```php
4+
The PHP examples in this documentation will assume you are using the WooCommerce client from Automattic to connect to the WooCommerce REST API, which you can require in your project via Composer:
5+
6+
$ composer require automattic/woocommerce
7+
8+
You will then need to configure and instantiate the client in your project, like so:
9+
10+
<?php
11+
12+
require __DIR__ . '/vendor/autoload.php';
13+
14+
use Automattic\WooCommerce\Client;
15+
16+
$woocommerce = new Client(
17+
'http://example.com', // Your store URL
18+
'consumer_key', // Your consumer key
19+
'consumer_secret', // Your consumer secret
20+
[
21+
'wp_api' => true, // Enable the WP REST API integration
22+
'version' => 'wc/v2' // WooCommerce WP REST API version
23+
]
24+
);
25+
26+
?>
27+
```
28+
29+
Welcome to the [WooCommerce Memberships](https://woocommerce.com/products/woocommerce-memberships/) REST API documentation!
30+
31+
Since version 1.11.0, Memberships extends [WooCommerce](https://woocommerce.com/) and builds upon the [WordPress REST API](http://v2.wp-api.org/) to handle user memberships and memberships plans data through robust REST API endpoints.
32+
33+
Memberships currently supports v2 of the WooCommerce REST API extension for WordPress, therefore all its endpoints will be added to the `/wc/v2/` route.
34+
35+
This documentation showcases the available HTTP API methods and endpoints to perform valid requests, along with some examples in PHP.
36+
37+
If you spot a typo, an error, have a question, want to provide feedback or extend the documentation, please refer to the [GitHub repository of this documentation](https://github.com/skyverge/woocommerce-memberships-rest-api-docs).
38+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Membership Plans
2+
3+
## The Membership Plan
4+
5+
A membership plan is a collection of settings and conditions according to which customers can get access to restricted content, products, get member only discounts and so on.
6+
7+
### Data Structure
8+
9+
A membership plan has the following data structure in the REST API:
10+
11+
Property | Type | Description
12+
------------------------------------ | ----------------------------------------| ------------
13+
`id` | <code>int</code> | The unique identifier (integer) of the membership plan.
14+
`name` | <code>string</code> | The membership plan name.
15+
`slug` | <code>string</code> | The membership plan slug (a unique string identifier).
16+
`status` | <code>string</code> | The membership plan status (this usually matches standard WordPress post statuses, with _`publish`_ or _`draft`_ being the most common for plans).
17+
`access_method` | <code>string</code> | The method that membership plan prescribes for users to gain access.
18+
`has_subscription` | <code>bool</code> | Whether the plan has at least one subscription among the products that can grant access.<sup><a href="#membership-plan-data-subscriptions-inactive">1</a></sup>
19+
`has_subscription_installment` | <code>bool</code> | Whether the plan uses the subscription for managing installment plans (the membership plan length is not directly tied to the subscription length).<sup><a href="#membership-plan-data-subscriptions-inactive">1</a></sup>
20+
`access_product_ids` | <code>int[]</code> | An optional array of product IDs (integers) to products that will grant access to the membership plan upon purchase. If no products grant access to the membership plan, the value will be an empty array.
21+
`access_length_type` | <code>string</code> | The access length type: specific (relative dates), fixed (fixed dates) or unlimited.
22+
`subscription_access_length_type` | <code>string</code> | The access length type when the product that granted access to the plan is a subscription: subscription (access lasts as long as the subscription does), specific (relative dates), fixed (fixed dates) or unlimited.<sup><a href="#membership-plan-data-subscriptions-inactive">1</a></sup>
23+
`access_length` | <code>int&#124;null</code> | The length in seconds that a user membership created for this plan will have, by default. This could be null for unlimited memberships that have no set end (or may be tied to a subscription).
24+
`subcription_access_length` | <code>int&#124;null</code> | When access to the plan is tied to a subscription, the length in seconds that a corresponding user membership will have. This could be null if it lasts as long as the subscription is active or the plan does not have a subscription product that can grant access.<sup><a href="#membership-plan-data-subscriptions-inactive">1</a></sup>
25+
`access_start_date` | <code>datetime&#124;null</code> | If the plan length type is based on fixed dates, this will be the date when any user membership will start, otherwise it will be _`null`_.
26+
`access_start_date_gmt` | <code>datetime&#124;null</code> | If the plan length type is based on fixed dates, this will be the date when any user membership will start, otherwise it will be _`null`_.<sup><a href="#membership-plan-data-subscriptions-inactive">1</a></sup>
27+
`access_end_date` | <code>datetime&#124;null</code> | If the plan length type is fixed this will be a fixed date when any membership will end, otherwise it will be _`null`_.
28+
`access_end_date_gmt` | <code>datetime&#124;null</code> | If the plan length type is fixed this will be a fixed date when any membership will end, otherwise it will be _`null`_.
29+
`subscription_access_start_date` | <code>datetime&#124;null</code> | When access to the plan is tied to a subscription and the plan length type is based on fixed dates, this will be the date when any user membership will start, otherwise it will be _`null`_.<sup><a href="#membership-plan-data-subscriptions-inactive">1</a></sup>
30+
`subscription_access_start_date_gmt` | <code>datetime&#124;null</code> | When access to the plan is tied to a subscription and the plan length type is based on fixed dates, this will be the date when any user membership will start, otherwise it will be _`null`_.<sup><a href="#membership-plan-data-subscriptions-inactive">1</a></sup>
31+
`subscription_access_end_date` | <code>datetime&#124;null</code> | When access to the plan is tied to a subscription and the plan length type is fixed this will be a fixed date when any membership will end, otherwise it will be _`null`_.<sup><a href="#membership-plan-data-subscriptions-inactive">1</a></sup>
32+
`subscription_access_end_date_gmt` | <code>datetime&#124;null</code> | When access to the plan is tied to a subscription and the plan length type is fixed this will be a fixed date when any membership will end, otherwise it will be _`null`_.<sup><a href="#membership-plan-data-subscriptions-inactive">1</a></sup>
33+
`date_created` | <code>datetime</code> | The date (in Atom format) when the membership plan object was created, in the local timezone.
34+
`date_created_gmt` | <code>datetime</code> | The date (in Atom format) when the membership plan object was created, in UTC.
35+
`date_modified` | <code>datetime</code> | The date (in Atom format) when the membership plan object was last modified, in the local timezone.
36+
`date_modified_gmt` | <code>datetime</code> | The date (in Atom format) when the membership plan object was last modified, in UTC.
37+
`meta_data` | <code>array</code> | Holds any WordPress meta data set on the plan. Each array item has an "id" _`(integer)`_, a "key" _`(string)`_ and a "value" (either a _`boolean`_, an _`integer`_, or _`string`_, which could also represent serialized data).
38+
`links` | <code>array</code> | An array of items linking to related objects accessible through the REST API.
39+
40+
41+
**Notes:**
42+
43+
<sup id="membership-plan-data-subscriptions-inactive">1</sup> If WooCommerce Subscriptions is inactive this field will not exist.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# User Memberships
2+
3+
## The User Membership
4+
5+
A user membership is created when a customer gets access to a membership plan, therefore all user memberships are linked to one user and one membership plan only. Also, a membership has a status and a start date.
6+
7+
### Data Structure
8+
9+
A user membership has the following data structure in the REST API:
10+
11+
Property | Type | Description
12+
-------------------- | --------------------------------| ------------
13+
`id` | <code>int</code> | The unique identifier (integer) of the user membership.
14+
`customer_id` | <code>int</code> | The unique identifier (integer) of the customer that owns the membership.
15+
`plan_id` | <code>int</code> | The unique identifier (integer) of the membership plan the membership is for.
16+
`status` | <code>string</code> | The current status (string) of the user membership.
17+
`order_id` | <code>int&#124;null</code> | The unique identifier (integer) of the order that may have granted access to the matching membership plan. If the user membership is not linked to an order, it will return _`null`_.
18+
`subscription_id` | <code>int&#124;null</code> | The unique identifier (integer) of a subscription that may be linked to the user membership. This property will exist only if the site is running WooCommerce Subscriptions alongside with Memberships. If there is no link to a subscription, the value will be _`null`_.<sup><a href="#user-membership-data-subscriptions-inactive">1</a></sup>
19+
`product_id` | <code>int&#124;null</code> | The unique identifier (integer) of a product that may have granted access to the matching membership plan. If the user membership is not linked to a product, it will return _`null`_.
20+
`date_created` | <code>datetime</code> | The date (in Atom format) when the user membership object was created, in the local timezone. This does not necessarily match with the start date.
21+
`date_created_gmt` | <code>datetime</code> | The date (in Atom format) when the user membership object was created, in UTC. This does not necessarily match with the start date.
22+
`start_date` | <code>datetime</code> | The date (in Atom format) when the membership starts, in the local timezone.
23+
`start_date_gmt` | <code>datetime</code> | The date (in Atom format) when the membership starts, in UTC.
24+
`end_date` | <code>datetime&#124;null</code> | The date (in Atom format) when the ends, in the local timezone. This is `null` if the membership doesn't have an end date.
25+
`end_date_gmt` | <code>datetime&#124;null</code> | The date (in Atom format) when the ends, in UTC. This is `null` if the membership doesn't have an end date.
26+
`paused_date` | <code>datetime&#124;null</code> | The date (in Atom format) when the membership was last paused, in the local timezone. This is `null` if the membership was never paused. The value is not removed if the membership changes status.
27+
`paused_date_gmt` | <code>datetime&#124;null</code> | The date (in Atom format) when the membership was last paused, in UTC. This is `null` if the membership was never paused. The value is not removed if the membership changes status.
28+
`cancelled_date` | <code>datetime&#124;null</code> | The date (in Atom format) when the membership was cancelled, in the local timezone. This is `null` if the membership was not cancelled.
29+
`cancelled_date_gmt` | <code>datetime&#124;null</code> | The date (in Atom format) when the membership was cancelled, in UTC. This is `null` if the membership was not cancelled.
30+
`view_url` | <code>string</code> | URL pointing to the site's Members Area accessible to the membership's owner.
31+
`meta_data` | <code>array</code> | Holds any WordPress meta data set on the membership. Each array item has an "id" _`(integer)`_, a "key" _`(string)`_ and a "value" (either a _`boolean`_, an _`integer`_, or _`string`_, which could also represent serialized data).
32+
`links` | <code>array</code> | An array of items linking to related objects accessible through the REST API.
33+
34+
35+
**Notes:**
36+
37+
<sup id="user-membership-data-subscriptions-inactive">1</sup> If WooCommerce Subscriptions is inactive this field will not exist.

source/includes/_webhooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
WooCommerce Memberships extends WooCommerce with custom webhooks that are triggered when changes occur to User Memberships or Membership Plan objects.
44

5-
## Membership Plan WebHooks
5+
## User Membership WebHooks
66

77
Each of the following webhooks will send a corresponding [user membership object](/woocommerce-memberships-rest-api-docs#the-user-membership) as payload.
88

0 commit comments

Comments
 (0)