Back to Woocommerce

Shipping zone locations

docs/apis/rest-api/v3/shipping-zone-locations.mdx

10.9.0-dev4.3 KB
Original Source

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

Shipping zone locations

The shipping zone locations API allows you to view and batch update locations of a shipping zone.

Shipping location properties

AttributeTypeDescription
codestringShipping zone location code.
typestringShipping zone location type. Options: postcode, state, country and continent. Default is country.

List all locations of a shipping zone

This API helps you to view all the locations of a shipping zone.

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

Update a locations of a shipping zone

This API lets you make changes to locations of a shipping zone.

http
PUT /wp-json/wc/v3/shipping/zones/<id>/locations
<Tabs> <TabItem value="curl" label="cURL">
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"
  }
]'
</TabItem> <TabItem value="js" label="JavaScript">
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 );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$data = [
    [
        'code' => 'BR:SP',
        'type' => 'state'
    ],
    [
        'code' => 'BR:RJ',
        'type' => 'state'
    ]
];

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

print(wcapi.put("shipping/zones/5/locations", data).json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
data = [
  {
    code: "BR:SP",
    type: "state"
  },
  {
    code: "BR:RJ",
    type: "state"
  }
]

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