Back to Woocommerce

Order actions

docs/apis/rest-api/v3/order-actions.mdx

10.9.0-dev6.7 KB
Original Source

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

Order actions

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.

Note: currently only some actions are available, other actions will be introduced at a later time.

Send order details to customer

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.

http
POST /wp-json/wc/v3/orders/<id>/actions/send_order_details
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X POST https://example.com/wp-json/wc/v3/orders/723/actions/send_order_details \
	-u consumer_key:consumer_secret \
	-d '{
	  "email": "[email protected]",
	  "force_email_update": true
	}'
</TabItem> <TabItem value="js" label="JavaScript">
javascript
const data = {
	email: '[email protected]',
	force_email_update: true,
};

WooCommerce.post( 'orders/723/actions/send_order_details', data )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$data = [
    'email' => '[email protected]',
    'force_email_update' => true,
];

print_r($woocommerce->post('orders/723/actions/send_order_details', $data));
?>
</TabItem> <TabItem value="python" label="Python">
python
data = {
    "email": "[email protected]",
    "force_email_update": true
}

print(wcapi.post("orders/723/actions/send_order_details", data).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
data = {
    "email": "[email protected]",
    "force_email_update": true
}

woocommerce.post("orders/723/actions/send_order_details", data).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"message": "Billing email updated to [email protected]. Order details sent to [email protected], via REST API."
}
</TabItem> </Tabs>
json
{
	"code": "woocommerce_rest_missing_email",
	"message": "Order does not have an email address.",
	"data": {
		"status": 400
	}
}

Send order notification email to customer

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 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.

http
POST /wp-json/wc/v3/orders/<id>/actions/send_email
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X POST https://example.com/wp-json/wc/v3/orders/723/actions/send_email \
	-u consumer_key:consumer_secret \
	-d '{
	  "template_id": "customer_completed_order",
	  "email": "[email protected]",
	  "force_email_update": true
	}'
</TabItem> <TabItem value="js" label="JavaScript">
javascript
const data = {
	template_id: 'customer_completed_order',
	email: '[email protected]',
	force_email_update: true,
};

WooCommerce.post( 'orders/723/actions/send_email', data )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$data = [
    'template_id' => 'customer_completed_order',
    'email' => '[email protected]',
    'force_email_update' => true,
];

print_r($woocommerce->post('orders/723/actions/send_email', $data));
?>
</TabItem> <TabItem value="python" label="Python">
python
data = {
    "template_id": "customer_completed_order",
    "email": "[email protected]",
    "force_email_update": true
}

print(wcapi.post("orders/723/actions/send_email", data).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
data = {
    "template_id": "customer_completed_order",
    "email": "[email protected]",
    "force_email_update": true
}

woocommerce.post("orders/723/actions/send_email", data).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"message": "Billing email updated to [email protected]. Email template &quot;Completed order&quot; sent to [email protected], via REST API."
}
</TabItem> </Tabs>
json
{
	"code": "woocommerce_rest_invalid_email_template",
	"message": "customer_completed_order is not a valid template for this order.",
	"data": {
		"status": 400
	}
}

Get available email templates for an order

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.

http
GET /wp-json/wc/v3/orders/<id>/actions/email_templates
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X GET https://example.com/wp-json/wc/v3/orders/723/actions/email_templates \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'orders/723/actions/email_templates' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
print_r($woocommerce->get('orders/723/actions/email_templates'));
?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("orders/723/actions/email_templates").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.post("orders/723/actions/email_templates").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"id": "customer_completed_order",
		"title": "Completed order",
		"description": "Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped."
	},
	{
		"id": "customer_invoice",
		"title": "Order details",
		"description": "Order detail emails can be sent to customers containing their order information and payment links."
	}
]
</TabItem> </Tabs>