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


配送区域位置

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

配送位置属性

属性 类型 描述
code string 配送区域位置代码。
type string 配送区域位置类型。选项:postcodestatecountrycontinent。默认为 country

列出配送区域的所有位置

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

HTTP 请求

GET
/wp-json/wc/v3/shipping/zones/<id>/locations
curl https://example.com/wp-json/wc/v3/shipping/zones/5/locations \
    -u consumer_key:consumer_secret
WooCommerce.get("shipping/zones/5/locations")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php print_r($woocommerce->get('shipping/zones/5/locations')); ?>
print(wcapi.get("shipping/zones/5/locations").json())
woocommerce.get("shipping/zones/5/locations").parsed_response

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 请求

PUT
/wp-json/wc/v3/shipping/zones/<id>/locations
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"
  }
]'
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
$data = [
    [
        'code' => 'BR:SP',
        'type' => 'state'
    ],
    [
        'code' => 'BR:RJ',
        'type' => 'state'
    ]
];

print_r($woocommerce->put('shipping/zones/5/locations', $data));
?>
data = [
    {
        "code": "BR:SP",
        "type": "state"
    },
    {
        "code": "BR:RJ",
        "type": "state"
    }
]

print(wcapi.put("shipping/zones/5/locations", data).json())
data = [
  {
    code: "BR:SP",
    type: "state"
  },
  {
    code: "BR:RJ",
    type: "state"
  }
]

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

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"
        }
      ]
    }
  }
]