Back to Woocommerce

Shipping Zones Data Store

packages/js/data/src/shipping-zones/README.md

10.8.0-dev2.3 KB
Original Source

Shipping Zones Data Store

This data store provides functions to interact with the Shipping Zones REST endpoints. Under the hood this data store makes use of the CRUD data store.

Note: This data store is listed as experimental still as it is still in active development.

Usage

This data store can be accessed under the experimental/wc/admin/shipping/zones name. It is recommended you make use of the export store experimentalShippingZonesStore.

Example:

ts
import {
	experimentalShippingZonesStore,
} from '@woocommerce/data';
import { useDispatch } from '@wordpress/data';

function Component() {
	const actions = useDispatch(
		experimentalShippingZonesStore
	);
	actions.createShippingZone( { name: 'test' } );
}

Selections and actions

SelectorDescription
getShippingZone( id: number )Gets a Shipping Zone by ID
getShippingZoneError( id )Get the error for a failing GET shipping zone request.
getShippingZones( query = {} )Get all shipping zones, query object is empty.
getShippingZoneesError( query = {} )Get the error for a GET request for all shipping zones.

Example usage: wp.data.select( experimentalShippingZonesStore ).getShippingZone( 3 );

ActionsMethodDescription
createShippingZone( shippingZoneObject )POSTCreates shipping zone, see ShippingZone here for values
deleteShippingZone( id )DELETEDeletes a shipping class by ID
updatetShippingZone( id, shippingZoneObject )PUTUpdates a shipping zone, see ShippingZone here for values

Example usage: wp.data.dispatch( experimentalShippingZonesStore ).updateShippingZone( 3, { name: 'New name' } );