title: "配送区域 #" post_status: publish comment_status: open taxonomy: category: - woocommerce-rest-api post_tag: - Wp Api V2 - Includes - Source


配送区域

配送区域 API 允许您创建、查看、更新和删除单个配送区域。

配送区域属性

属性 类型 描述
id integer 资源的唯一标识符。只读
name string 配送区域名称。必填
order integer 配送区域排序。

创建配送区域

此 API 可帮助您创建新的配送区域。

HTTP 请求

POST
/wp-json/wc/v2/shipping/zones

JSON 响应示例:

curl -X POST https://example.com/wp-json/wc/v2/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

JSON 响应示例:

{
  "id": 5,
  "name": "Brazil",
  "order": 0,
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones/5"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones"
      }
    ],
    "describedby": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations"
      }
    ]
  }
}

获取配送区域

此 API 允许您通过 ID 检索并查看特定的配送区域。

HTTP 请求

GET
/wp-json/wc/v2/shipping/zones/<id>
curl https://example.com/wp-json/wc/v2/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

JSON 响应示例:

{
  "id": 5,
  "name": "Brazil",
  "order": 0,
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones/5"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones"
      }
    ],
    "describedby": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations"
      }
    ]
  }
}

List all shipping zones

This API helps you to view all the shipping zones.

HTTP request

GET
/wp-json/wc/v2/shipping/zones
curl https://example.com/wp-json/wc/v2/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

JSON response example:

[
  {
    "id": 0,
    "name": "Rest of the World",
    "order": 0,
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v2/shipping/zones/0"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v2/shipping/zones"
        }
      ],
      "describedby": [
        {
          "href": "https://example.com/wp-json/wc/v2/shipping/zones/0/locations"
        }
      ]
    }
  },
  {
    "id": 5,
    "name": "Brazil",
    "order": 0,
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v2/shipping/zones/5"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v2/shipping/zones"
        }
      ],
      "describedby": [
        {
          "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations"
        }
      ]
    }
  }
]

更新配送区域

此 API 允许您修改配送区域。

HTTP 请求

PUT
/wp-json/wc/v2/shipping/zones/<id>
curl -X PUT https://example.com/wp-json/wc/v2/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

JSON 响应示例:

{
  "id": 5,
  "name": "Brazil",
  "order": 1,
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones/5"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones"
      }
    ],
    "describedby": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations"
      }
    ]
  }
}

删除配送区域

此 API 可帮助您删除一个配送区域。

HTTP 请求

DELETE
/wp-json/wc/v2/shipping/zones/<id>
curl -X DELETE https://example.com/wp-json/wc/v2/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

JSON 响应示例:

{
  "id": 5,
  "name": "Brazil",
  "order": 1,
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones/5"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones"
      }
    ],
    "describedby": [
      {
        "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations"
      }
    ]
  }
}

Available parameters

Parameter Type Description
force string Required to be true, as resource does not support trashing.