将当前页面内容以 Markdown 格式复制到剪贴板
配送区域
配送区域 API 允许您创建、查看、更新和删除单个配送区域。
配送区域属性
| 属性 | 类型 | 描述 |
|---|---|---|
id | integer | 该资源的唯一标识符。只读 |
name | 字符串 | 配送区域名称。必填 |
order | integer | 配送区域顺序。 |
创建一个配送区域
此 API 可帮助您创建新的配送区域。
POST /wp-json/wc/v3/shipping/zones
- cURL
- JavaScript
- PHP
- Python
- Ruby
- JSON Response
curl -X POST https://example.com/wp-json/wc/v3/shipping/zones \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "Brazil"
}'
const data = {
name: 'Brazil',
};
WooCommerce.post( 'shipping/zones', data )
.then( ( response ) => {
console.log( response.data );
} )
.catch( ( error ) => {
console.log( error.response.data );
} );
<?php
$data = [
'name' => 'Brazil'
];
print_r($woocommerce->post('shipping/zones', $data));
?>
data = {
"name": "Brazil"
}
print(wcapi.post("shipping/zones", data).json())
data = {
name: "Brazil"
}
woocommerce.post("shipping/zones", data).parsed_response
{
"id": 5,
"name": "Brazil",
"order": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones"
}
],
"describedby": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations"
}
]
}
}
获取一个配送区域
这个 API 允许您通过编号检索并查看特定的配送区域。
GET /wp-json/wc/v3/shipping/zones/<id>
- cURL
- JavaScript
- PHP
- Python
- Ruby
- JSON Response
curl https://example.com/wp-json/wc/v3/shipping/zones/5 \
-u consumer_key:consumer_secret
WooCommerce.get( 'shipping/zones/5' )
.then( ( response ) => {
console.log( response.data );
} )
.catch( ( error ) => {
console.log( error.response.data );
} );
<?php print_r($woocommerce->get('shipping/zones/5')); ?>
print(wcapi.get("shipping/zones/5").json())
woocommerce.get("shipping/zones/5").parsed_response
{
"id": 5,
"name": "Brazil",
"order": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones"
}
],
"describedby": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations"
}
]
}
}
列出所有配送区域
此 API 帮助您查看全部的配送区域。
GET /wp-json/wc/v3/shipping/zones
- cURL
- JavaScript
- PHP
- Python
- Ruby
- JSON Response
curl https://example.com/wp-json/wc/v3/shipping/zones \
-u consumer_key:consumer_secret
WooCommerce.get( 'shipping/zones' )
.then( ( response ) => {
console.log( response.data );
} )
.catch( ( error ) => {
console.log( error.response.data );
} );
<?php print_r($woocommerce->get('shipping/zones')); ?>
print(wcapi.get("shipping/zones").json())
woocommerce.get("shipping/zones").parsed_response
[
{
"id": 0,
"name": "Rest of the World",
"order": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/0"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones"
}
],
"describedby": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/0/locations"
}
]
}
},
{
"id": 5,
"name": "Brazil",
"order": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones"
}
],
"describedby": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations"
}
]
}
}
]
更新一个配送区域
这个 API 允许您对一个配送区域进行更改。
PUT /wp-json/wc/v3/shipping/zones/<id>
- cURL
- JavaScript
- PHP
- Python
- Ruby
- JSON Response
curl -X PUT https://example.com/wp-json/wc/v3/shipping/zones/5 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"order": 1
}'
const data = {
order: 1,
};
WooCommerce.put( 'shipping/zones/5', data )
.then( ( response ) => {
console.log( response.data );
} )
.catch( ( error ) => {
console.log( error.response.data );
} );
<?php
$data = [
'order' => 1
];
print_r($woocommerce->put('shipping/zones/5', $data));
?>
data = {
"order": 1
}
print(wcapi.put("shipping/zones/5", data).json())
data = {
order: 1
}
woocommerce.put("shipping/zones/5", data).parsed_response
{
"id": 5,
"name": "Brazil",
"order": 1,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones"
}
],
"describedby": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations"
}
]
}
}
删除一个配送区域
这个 API 可以帮助您删除一个配送区域。
DELETE /wp-json/wc/v3/shipping/zones/<id>
- cURL
- JavaScript
- PHP
- Python
- Ruby
- JSON Response
curl -X DELETE https://example.com/wp-json/wc/v3/shipping/zones/5?force=true \
-u consumer_key:consumer_secret
WooCommerce.delete( 'shipping/zones/5', {
force: true,
} )
.then( ( response ) => {
console.log( response.data );
} )
.catch( ( error ) => {
console.log( error.response.data );
} );
<?php print_r($woocommerce->delete('shipping/zones/5', ['force' => true])); ?>
print(wcapi.delete("shipping/zones/5", params={"force": True}).json())
woocommerce.delete("shipping/zones/5", force: true).parsed_response
{
"id": 5,
"name": "Brazil",
"order": 1,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones"
}
],
"describedby": [
{
"href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations"
}
]
}
}
Available parameters
| Parameter | Type | Description |
|---|---|---|
force | string | Required to be true, as resource does not support trashing. |