Back to Woocommerce

Shipping zones

docs/apis/rest-api/v3/shipping-zones.mdx

10.9.0-dev8.4 KB
Original Source

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

Shipping zones

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

Shipping zone properties

AttributeTypeDescription
idintegerUnique identifier for the resource. READ-ONLY
namestringShipping zone name. MANDATORY
orderintegerShipping zone order.

Create a shipping zone

This API helps you to create a new shipping zone.

http
POST /wp-json/wc/v3/shipping/zones
<Tabs> <TabItem value="curl" label="cURL">
shell
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"
}'
</TabItem> <TabItem value="js" label="JavaScript">
javascript
const data = {
	name: 'Brazil',
};

WooCommerce.post( 'shipping/zones', data )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$data = [
    'name' => 'Brazil'
];

print_r($woocommerce->post('shipping/zones', $data));
?>
</TabItem> <TabItem value="python" label="Python">
python
data = {
    "name": "Brazil"
}

print(wcapi.post("shipping/zones", data).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
data = {
  name: "Brazil"
}

woocommerce.post("shipping/zones", data).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"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"
			}
		]
	}
}
</TabItem> </Tabs>

Retrieve a shipping zone

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

http
GET /wp-json/wc/v3/shipping/zones/<id>
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/shipping/zones/5 \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'shipping/zones/5' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->get('shipping/zones/5')); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("shipping/zones/5").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("shipping/zones/5").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"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"
			}
		]
	}
}
</TabItem> </Tabs>

List all shipping zones

This API helps you to view all the shipping zones.

http
GET /wp-json/wc/v3/shipping/zones
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/shipping/zones \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'shipping/zones' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->get('shipping/zones')); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("shipping/zones").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("shipping/zones").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"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"
				}
			]
		}
	}
]
</TabItem> </Tabs>

Update a shipping zone

This API lets you make changes to a shipping zone.

http
PUT /wp-json/wc/v3/shipping/zones/<id>
<Tabs> <TabItem value="curl" label="cURL">
shell
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
}'
</TabItem> <TabItem value="js" label="JavaScript">
javascript
const data = {
	order: 1,
};

WooCommerce.put( 'shipping/zones/5', data )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$data = [
    'order' => 1
];

print_r($woocommerce->put('shipping/zones/5', $data));
?>
</TabItem> <TabItem value="python" label="Python">
python
data = {
    "order": 1
}

print(wcapi.put("shipping/zones/5", data).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
data = {
  order: 1
}

woocommerce.put("shipping/zones/5", data).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"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"
			}
		]
	}
}
</TabItem> </Tabs>

Delete a shipping zone

This API helps you delete a shipping zone.

http
DELETE /wp-json/wc/v3/shipping/zones/<id>
<Tabs> <TabItem value="curl" label="cURL">
shell
curl -X DELETE https://example.com/wp-json/wc/v3/shipping/zones/5?force=true \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.delete( 'shipping/zones/5', {
	force: true,
} )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->delete('shipping/zones/5', ['force' => true])); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.delete("shipping/zones/5", params={"force": True}).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.delete("shipping/zones/5", force: true).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
{
	"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"
			}
		]
	}
}
</TabItem> </Tabs>

Available parameters

ParameterTypeDescription
forcestringRequired to be true, as resource does not support trashing.