woocommerce-rest-api-docs/source/includes/wp-api-v3/_shipping-zones.md
2019-07-29 20:22:31 -03:00

7.8 KiB

Shipping zones

The shipping zones API allows you to create, view, update, and delete individual shipping zones.

Shipping zone properties

Attribute Type Description
id integer Unique identifier for the resource. read-only
name string Shipping zone name. mandatory
order integer Shipping zone order.

Create a shipping zone

This API helps you to create a new shipping zone.

HTTP request

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

JSON response example:

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

JSON response example:

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

Retrieve a shipping zone

This API lets you retrieve and view a specific shipping zone by ID.

HTTP request

GET
/wp-json/wc/v3/shipping/zones/<id>
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

JSON response example:

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

List all shipping zones

This API helps you to view all the shipping zones.

HTTP request

GET
/wp-json/wc/v3/shipping/zones
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

JSON response example:

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

Update a shipping zone

This API lets you make changes to a shipping zone.

HTTP request

PUT
/wp-json/wc/v3/shipping/zones/<id>
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

JSON response example:

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

Delete a shipping zone

This API helps you delete a shipping zone.

HTTP request

DELETE
/wp-json/wc/v3/shipping/zones/<id>
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

JSON response example:

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