# 配送区域位置 #

配送区域位置 API 允许您查看和批量更新配送区域的位置。

## 配送位置属性 ##

| 属性 | 类型   | 描述                                                                                                 |
| --------- | ------ | ----------------------------------------------------------------------------------------------------------- |
| `code`    | string | 配送区域位置代码。                                                                                |
| `type`    | string | 配送区域位置类型。选项：`postcode`、`state`、`country` 和 `continent`。默认为 `country`。 |

## 列出配送区域的所有位置 ##

此 API 可帮助您查看配送区域的所有位置。

### HTTP 请求 ###

<div class="api-endpoint">
	<div class="endpoint-data">
		<i class="label label-get">GET</i>
		<h6>/wp-json/wc/v3/shipping/zones/&lt;id&gt;/locations</h6>
	</div>
</div>

```shell
curl https://example.com/wp-json/wc/v3/shipping/zones/5/locations \
	-u consumer_key:consumer_secret
```

```javascript
WooCommerce.get("shipping/zones/5/locations")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
```

```php
<?php print_r($woocommerce->get('shipping/zones/5/locations')); ?>
```

```python
print(wcapi.get("shipping/zones/5/locations").json())
```

```ruby
woocommerce.get("shipping/zones/5/locations").parsed_response
```

> JSON 响应示例：

```json
[
  {
    "code": "BR",
    "type": "country",
    "_links": {
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations"
        }
      ],
      "describes": [
        {
          "href": "https://example.com/wp-json/wc/v3/shipping/zones/5"
        }
      ]
    }
  }
]
```

## 更新配送区域的位置 ##

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

### HTTP 请求 ###

<div class="api-endpoint">
	<div class="endpoint-data">
		<i class="label label-put">PUT</i>
		<h6>/wp-json/wc/v3/shipping/zones/&lt;id&gt;/locations</h6>
	</div>
</div>

```shell
curl -X PUT https://example.com/wp-json/wc/v3/shipping/zones/5/locations \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '[
  {
    "code": "BR:SP",
    "type": "state"
  },
  {
    "code": "BR:RJ",
    "type": "state"
  }
]'
```

```javascript
var data = [
  {
    code: 'BR:SP',
    type: 'state'
  },
  {
    code: 'BR:RJ',
    type: 'state'
  }
];

WooCommerce.put("shipping/zones/5/locations", data)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
```

```php
<?php
$data = [
    [
        'code' => 'BR:SP',
        'type' => 'state'
    ],
    [
        'code' => 'BR:RJ',
        'type' => 'state'
    ]
];

print_r($woocommerce->put('shipping/zones/5/locations', $data));
?>
```

```python
data = [
    {
        "code": "BR:SP",
        "type": "state"
    },
    {
        "code": "BR:RJ",
        "type": "state"
    }
]

print(wcapi.put("shipping/zones/5/locations", data).json())
```

```ruby
data = [
  {
    code: "BR:SP",
    type: "state"
  },
  {
    code: "BR:RJ",
    type: "state"
  }
]

woocommerce.put("shipping/zones/5/locations", data).parsed_response
```

> JSON 响应示例：

```json
[
  {
    "code": "BR:SP",
    "type": "state",
    "_links": {
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations"
        }
      ],
      "describes": [
        {
          "href": "https://example.com/wp-json/wc/v3/shipping/zones/5"
        }
      ]
    }
  },
  {
    "code": "BR:RJ",
    "type": "state",
    "_links": {
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations"
        }
      ],
      "describes": [
        {
          "href": "https://example.com/wp-json/wc/v3/shipping/zones/5"
        }
      ]
    }
  }
]
```