Skip to content

Commit 0c71466

Browse files
authored
Merge pull request #260 from woocommerce/update/order-actions-emails
Add docs for new email-related order actions endpoints
2 parents dbe389e + 51d92d4 commit 0c71466

File tree

2 files changed

+192
-8
lines changed

2 files changed

+192
-8
lines changed

source/includes/wp-api-v3/_order-actions.md

Lines changed: 180 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
The order actions API allows you to perform specific actions with existing orders like you can from the Edit Order screen in the web app.
44

5-
_Note: currently only one action is available, other actions will be introduced at a later time._
5+
_Note: currently only some actions are available, other actions will be introduced at a later time._
66

77
## Send order details to customer ##
88

9-
This endpoint allows you to trigger an email to the customer with the details of their order, if the order contains a customer email address.
9+
This endpoint allows you to trigger an email to the customer with the details of their order. In case the order doesn't yet have a billing email set, you can specify an email recipient. However, if the order does have an existing billing email, this will return an error, unless you also specify that the existing email should be overwritten by using the `force_email_update` parameter.
1010

1111
### HTTP request ###
1212

@@ -19,11 +19,20 @@ This endpoint allows you to trigger an email to the customer with the details of
1919

2020
```shell
2121
curl -X POST https://example.com/wp-json/wc/v3/orders/723/actions/send_order_details \
22-
-u consumer_key:consumer_secret
22+
-u consumer_key:consumer_secret \
23+
-d '{
24+
"email": "[email protected]",
25+
"force_email_update": true
26+
}'
2327
```
2428

2529
```javascript
26-
WooCommerce.post("orders/723/actions/send_order_details")
30+
const data = {
31+
32+
force_email_update: true
33+
};
34+
35+
WooCommerce.post("orders/723/actions/send_order_details", data)
2736
.then((response) => {
2837
console.log(response.data);
2938
})
@@ -34,23 +43,38 @@ WooCommerce.post("orders/723/actions/send_order_details")
3443

3544
```php
3645
<?php
37-
print_r($woocommerce->post('orders/723/actions/send_order_details'));
46+
$data = [
47+
'email' => '[email protected]',
48+
'force_email_update' => true,
49+
];
50+
51+
print_r($woocommerce->post('orders/723/actions/send_order_details', $data));
3852
?>
3953
```
4054

4155
```python
42-
print(wcapi.post("orders/723/actions/send_order_details").json())
56+
data = {
57+
"email": "[email protected]",
58+
"force_email_update": true
59+
}
60+
61+
print(wcapi.post("orders/723/actions/send_order_details", data).json())
4362
```
4463

4564
```ruby
46-
woocommerce.post("orders/723/actions/send_order_details").parsed_response
65+
data = {
66+
"email": "[email protected]",
67+
"force_email_update": true
68+
}
69+
70+
woocommerce.post("orders/723/actions/send_order_details", data).parsed_response
4771
```
4872

4973
> JSON response examples:
5074
5175
```json
5276
{
53-
"message": "Order details sent to woo@example.com, via REST API."
77+
"message": "Billing email updated to [email protected]. Order details sent to somebody@example.com, via REST API."
5478
}
5579
```
5680

@@ -63,3 +87,151 @@ woocommerce.post("orders/723/actions/send_order_details").parsed_response
6387
}
6488
}
6589
```
90+
91+
## Send order notification email to customer ##
92+
93+
This endpoint allows you to trigger an email to a customer about the status of their order. This is similar to the [`send_order_details`](#send-order-details-to-customer) endpoint, but allows you to specify which email template to send, based on which email templates are relevant to the order. For example, an order that is on hold has the `customer_on_hold_order` template available. A completed order that also has a partial refund has both the `customer_completed_order` and `customer_refunded_order` templates available. Specifying the `customer_invoice` template is the same as using the `send_order_details` endpoint.
94+
95+
### HTTP request ###
96+
97+
<div class="api-endpoint">
98+
<div class="endpoint-data">
99+
<i class="label label-post">POST</i>
100+
<h6>/wp-json/wc/v3/orders/&lt;id&gt;/actions/send_email</h6>
101+
</div>
102+
</div>
103+
104+
```shell
105+
curl -X POST https://example.com/wp-json/wc/v3/orders/723/actions/send_email \
106+
-u consumer_key:consumer_secret \
107+
-d '{
108+
"template_id": "customer_completed_order",
109+
"email": "[email protected]",
110+
"force_email_update": true
111+
}'
112+
```
113+
114+
```javascript
115+
const data = {
116+
template_id: "customer_completed_order",
117+
118+
force_email_update: true
119+
};
120+
121+
WooCommerce.post("orders/723/actions/send_email", data)
122+
.then((response) => {
123+
console.log(response.data);
124+
})
125+
.catch((error) => {
126+
console.log(error.response.data);
127+
});
128+
```
129+
130+
```php
131+
<?php
132+
$data = [
133+
'template_id' => 'customer_completed_order',
134+
'email' => '[email protected]',
135+
'force_email_update' => true,
136+
];
137+
138+
print_r($woocommerce->post('orders/723/actions/send_email', $data));
139+
?>
140+
```
141+
142+
```python
143+
data = {
144+
"template_id": "customer_completed_order",
145+
"email": "[email protected]",
146+
"force_email_update": true
147+
}
148+
149+
print(wcapi.post("orders/723/actions/send_email", data).json())
150+
```
151+
152+
```ruby
153+
data = {
154+
"template_id": "customer_completed_order",
155+
"email": "[email protected]",
156+
"force_email_update": true
157+
}
158+
159+
woocommerce.post("orders/723/actions/send_email", data).parsed_response
160+
```
161+
162+
> JSON response examples:
163+
164+
```json
165+
{
166+
"message": "Billing email updated to [email protected]. Email template &quot;Completed order&quot; sent to [email protected], via REST API."
167+
}
168+
```
169+
170+
```json
171+
{
172+
"code": "woocommerce_rest_invalid_email_template",
173+
"message": "customer_completed_order is not a valid template for this order.",
174+
"data": {
175+
"status": 400
176+
}
177+
}
178+
```
179+
180+
## Get available email templates for an order ##
181+
182+
This endpoint allows you to retrieve a list of email templates that are available for the specified order. You can also get this data embedded in the response for the [`orders` endpoint](#list-all-orders).
183+
184+
### HTTP request ###
185+
186+
<div class="api-endpoint">
187+
<div class="endpoint-data">
188+
<i class="label label-get">GET</i>
189+
<h6>/wp-json/wc/v3/orders/&lt;id&gt;/actions/email_templates</h6>
190+
</div>
191+
</div>
192+
193+
```shell
194+
curl -X GET https://example.com/wp-json/wc/v3/orders/723/actions/email_templates \
195+
-u consumer_key:consumer_secret
196+
```
197+
198+
```javascript
199+
WooCommerce.get("orders/723/actions/email_templates")
200+
.then((response) => {
201+
console.log(response.data);
202+
})
203+
.catch((error) => {
204+
console.log(error.response.data);
205+
});
206+
```
207+
208+
```php
209+
<?php
210+
print_r($woocommerce->get('orders/723/actions/email_templates'));
211+
?>
212+
```
213+
214+
```python
215+
print(wcapi.get("orders/723/actions/email_templates").json())
216+
```
217+
218+
```ruby
219+
woocommerce.post("orders/723/actions/email_templates").parsed_response
220+
```
221+
222+
> JSON response examples:
223+
224+
```json
225+
[
226+
{
227+
"id": "customer_completed_order",
228+
"title": "Completed order",
229+
"description": "Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped."
230+
},
231+
{
232+
"id": "customer_invoice",
233+
"title": "Order details",
234+
"description": "Order detail emails can be sent to customers containing their order information and payment links."
235+
}
236+
]
237+
```

source/includes/wp-api-v3/_orders.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,12 @@ woocommerce.get("orders").parsed_response
10181018
{
10191019
"href": "https://example.com/wp-json/wc/v3/orders"
10201020
}
1021+
],
1022+
"email_templates": [
1023+
{
1024+
"embeddable": true,
1025+
"href": "http://example.com/wp-json/wc/v3/orders/723/actions/email_templates"
1026+
}
10211027
]
10221028
}
10231029
},
@@ -1162,6 +1168,12 @@ woocommerce.get("orders").parsed_response
11621168
"href": "https://example.com/wp-json/wc/v3/orders"
11631169
}
11641170
],
1171+
"email_templates": [
1172+
{
1173+
"embeddable": true,
1174+
"href": "http://example.com/wp-json/wc/v3/orders/723/actions/email_templates"
1175+
}
1176+
],
11651177
"customer": [
11661178
{
11671179
"href": "https://example.com/wp-json/wc/v3/customers/26"

0 commit comments

Comments
 (0)