WC_Shipping_Zone
extends WC_Legacy_Shipping_Zone
in package
WC_Shipping_Zone class.
Implemented by classes using the same CRUD(s) pattern.
Table of Contents
- $cache_group : string
- Stores meta in cache for future reads.
- $changes : array
- Core data changes for this object.
- $data : array
- Zone Data.
- $data_store : object
- Contains a reference to the data store for this class.
- $default_data : array
- Set to _data on construct so we can track and reset data if needed.
- $extra_data : array
- Extra data for this object. Name value pairs (name + default value).
- $id : int|null
- Zone ID
- $meta_data : array
- Stores additional meta data.
- $object_read : bool
- This is false until the object is read from the DB.
- $object_type : string
- This is the name of this object type.
- __clone() : mixed
- When the object is cloned, make sure meta is duplicated correctly.
- __construct() : mixed
- Constructor for zones.
- __sleep() : array
- Only store the object ID to avoid serializing the data object instance.
- __toString() : string
- Change data to JSON format.
- __wakeup() : mixed
- Re-run the constructor with the object ID.
- add_location() : mixed
- Add location (state or postcode) to a zone.
- add_meta_data() : mixed
- Add meta data.
- add_shipping_method() : int
- Add a shipping method to this zone.
- apply_changes() : mixed
- Merge changes with data and clear.
- clear_locations() : mixed
- Clear all locations for this zone.
- create() : mixed
- Create a zone.
- delete() : bool
- Delete an object, set the ID to 0, and return result.
- delete_meta_data() : mixed
- Delete meta data.
- delete_meta_data_by_mid() : mixed
- Delete meta data.
- delete_shipping_method() : true
- Delete a shipping method from a zone.
- get_changes() : array
- Return data changes only.
- get_data() : array
- Returns all data for this object.
- get_data_keys() : array
- Returns array of expected data keys for this object.
- get_data_store() : object
- Get the data store.
- get_extra_data_keys() : array
- Returns all "extra" data keys for an object (for sub objects like product types).
- get_formatted_location() : string
- Return a text string representing what this zone is for.
- get_id() : int
- Returns the unique ID for this object.
- get_meta() : mixed
- Get Meta Data by Key.
- get_meta_data() : array
- Get All Meta Data.
- get_object_read() : bool
- Get object read property.
- get_shipping_methods() : array
- Get shipping methods linked to this zone.
- get_zone_id() : int|null
- Get zone ID
- get_zone_locations() : array
- Get zone locations.
- get_zone_name() : string
- Get zone name.
- get_zone_order() : int
- Get zone order.
- is_valid_location_type() : bool
- Is passed location type valid?
- meta_exists() : bool
- See if meta data exists, since get_meta always returns a '' or array().
- read() : mixed
- Read a shipping zone by ID.
- read_meta_data() : mixed
- Read Meta Data from the database. Ignore any internal properties.
- save() : int
- Save zone data to the database.
- save_meta_data() : mixed
- Update Meta Data in the database.
- set_defaults() : mixed
- Set all props to default values.
- set_id() : mixed
- Set ID.
- set_locations() : mixed
- Set locations.
- set_meta_data() : mixed
- Set all meta data from array.
- set_object_read() : mixed
- Set object read property.
- set_props() : bool|WP_Error
- Set a collection of props in one go, collect any errors, and return the result.
- set_zone_locations() : mixed
- Set zone locations.
- set_zone_name() : mixed
- Set zone name.
- set_zone_order() : mixed
- Set zone order. Value to set.
- update() : mixed
- Update a zone.
- update_meta_data() : mixed
- Update meta data by key or ID, if provided.
- error() : mixed
- When invalid data is found, throw an exception unless reading from the DB.
- filter_null_meta() : bool
- Filter null meta values from array.
- generate_zone_name() : string
- Generate a zone name based on location.
- get_hook_prefix() : string
- Prefix for action and filter hooks on data.
- get_prop() : mixed
- Gets a prop for a getter method.
- is_internal_meta_key() : bool
- Check if the key is an internal one.
- maybe_read_meta_data() : mixed
- Read meta data if null.
- set_date_prop() : mixed
- Sets a date prop whilst handling formatting and datetime objects.
- set_prop() : mixed
- Sets a prop for a setter method.
- location_is_continent() : bool
- Location type detection.
- location_is_country() : bool
- Location type detection.
- location_is_postcode() : bool
- Location type detection.
- location_is_state() : bool
- Location type detection.
Properties
$cache_group
Stores meta in cache for future reads.
protected
string
$cache_group
= ''
A group must be set to to enable caching.
Tags
$changes
Core data changes for this object.
protected
array
$changes
= array()
Tags
$data
Zone Data.
protected
array
$data
= array('zone_name' => '', 'zone_order' => 0, 'zone_locations' => array())
$data_store
Contains a reference to the data store for this class.
protected
object
$data_store
Tags
$default_data
Set to _data on construct so we can track and reset data if needed.
protected
array
$default_data
= array()
Tags
$extra_data
Extra data for this object. Name value pairs (name + default value).
protected
array
$extra_data
= array()
Used as a standard way for sub classes (like product types) to add additional information to an inherited class.
Tags
$id
Zone ID
protected
int|null
$id
=
ull
$meta_data
Stores additional meta data.
protected
array
$meta_data
=
ull
Tags
$object_read
This is false until the object is read from the DB.
protected
bool
$object_read
= alse
Tags
$object_type
This is the name of this object type.
protected
string
$object_type
= 'shipping_zone'
Methods
__clone()
When the object is cloned, make sure meta is duplicated correctly.
public
__clone() : mixed
Tags
Return values
mixed__construct()
Constructor for zones.
public
__construct([int|object $zone = null ]) : mixed
Parameters
- $zone : int|object = null
-
Zone ID to load from the DB or zone object.
Return values
mixed__sleep()
Only store the object ID to avoid serializing the data object instance.
public
__sleep() : array
Return values
array__toString()
Change data to JSON format.
public
__toString() : string
Tags
Return values
string — Data in JSON format.__wakeup()
Re-run the constructor with the object ID.
public
__wakeup() : mixed
If the object no longer exists, remove the ID.
Return values
mixedadd_location()
Add location (state or postcode) to a zone.
public
add_location(string $code, string $type) : mixed
Parameters
- $code : string
-
Location code.
- $type : string
-
state or postcode.
Return values
mixedadd_meta_data()
Add meta data.
public
add_meta_data(string $key, string|array $value[, bool $unique = false ]) : mixed
Parameters
- $key : string
-
Meta key.
- $value : string|array
-
Meta value.
- $unique : bool = false
-
Should this be a unique key?.
Tags
Return values
mixedadd_shipping_method()
Add a shipping method to this zone.
public
add_shipping_method(string $type) : int
Parameters
- $type : string
-
shipping method type.
Return values
int — new instance_id, 0 on failureapply_changes()
Merge changes with data and clear.
public
apply_changes() : mixed
Tags
Return values
mixedclear_locations()
Clear all locations for this zone.
public
clear_locations([array|string $types = array('postcode', 'state', 'country', 'continent') ]) : mixed
Parameters
- $types : array|string = array('postcode', 'state', 'country', 'continent')
-
of location to clear.
Return values
mixedcreate()
Create a zone.
public
create() : mixed
Tags
Return values
mixeddelete()
Delete an object, set the ID to 0, and return result.
public
delete([bool $force_delete = false ]) : bool
Parameters
- $force_delete : bool = false
-
Should the date be deleted permanently.
Tags
Return values
bool — resultdelete_meta_data()
Delete meta data.
public
delete_meta_data(string $key) : mixed
Parameters
- $key : string
-
Meta key.
Tags
Return values
mixeddelete_meta_data_by_mid()
Delete meta data.
public
delete_meta_data_by_mid(int $mid) : mixed
Parameters
- $mid : int
-
Meta ID.
Tags
Return values
mixeddelete_shipping_method()
Delete a shipping method from a zone.
public
delete_shipping_method(int $instance_id) : true
Parameters
- $instance_id : int
-
Shipping method instance ID.
Return values
true — on success, false on failureget_changes()
Return data changes only.
public
get_changes() : array
Tags
Return values
arrayget_data()
Returns all data for this object.
public
get_data() : array
Tags
Return values
arrayget_data_keys()
Returns array of expected data keys for this object.
public
get_data_keys() : array
Tags
Return values
arrayget_data_store()
Get the data store.
public
get_data_store() : object
Tags
Return values
objectget_extra_data_keys()
Returns all "extra" data keys for an object (for sub objects like product types).
public
get_extra_data_keys() : array
Tags
Return values
arrayget_formatted_location()
Return a text string representing what this zone is for.
public
get_formatted_location([int $max = 10 ][, string $context = 'view' ]) : string
Parameters
- $max : int = 10
-
Max locations to return.
- $context : string = 'view'
-
View or edit context.
Return values
stringget_id()
Returns the unique ID for this object.
public
get_id() : int
Tags
Return values
intget_meta()
Get Meta Data by Key.
public
get_meta([string $key = '' ][, bool $single = true ][, string $context = 'view' ]) : mixed
Parameters
- $key : string = ''
-
Meta Key.
- $single : bool = true
-
return first found meta with key, or all with $key.
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
mixedget_meta_data()
Get All Meta Data.
public
get_meta_data() : array
Tags
Return values
array — of objects.get_object_read()
Get object read property.
public
get_object_read() : bool
Tags
Return values
boolget_shipping_methods()
Get shipping methods linked to this zone.
public
get_shipping_methods([bool $enabled_only = false ][, string $context = 'admin' ]) : array
Parameters
- $enabled_only : bool = false
-
Only return enabled methods.
- $context : string = 'admin'
-
Getting shipping methods for what context. Valid values, admin, json.
Return values
array — of objectsget_zone_id()
Get zone ID
public
get_zone_id() : int|null
Tags
Return values
int|null — Null if the zone does not exist. 0 is the default zone.get_zone_locations()
Get zone locations.
public
get_zone_locations([string $context = 'view' ]) : array
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
array — of zone objectsget_zone_name()
Get zone name.
public
get_zone_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
stringget_zone_order()
Get zone order.
public
get_zone_order([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
intis_valid_location_type()
Is passed location type valid?
public
is_valid_location_type(string $type) : bool
Parameters
- $type : string
-
Type to check.
Return values
boolmeta_exists()
See if meta data exists, since get_meta always returns a '' or array().
public
meta_exists([string $key = '' ]) : bool
Parameters
- $key : string = ''
-
Meta Key.
Tags
Return values
boolread()
Read a shipping zone by ID.
public
read(int $zone_id) : mixed
Parameters
- $zone_id : int
Tags
Return values
mixedread_meta_data()
Read Meta Data from the database. Ignore any internal properties.
public
read_meta_data([bool $force_read = false ]) : mixed
Uses it's own caches because get_metadata does not provide meta_ids.
Parameters
- $force_read : bool = false
-
True to force a new DB read (and update cache).
Tags
Return values
mixedsave()
Save zone data to the database.
public
save() : int
Return values
intsave_meta_data()
Update Meta Data in the database.
public
save_meta_data() : mixed
Tags
Return values
mixedset_defaults()
Set all props to default values.
public
set_defaults() : mixed
Tags
Return values
mixedset_id()
Set ID.
public
set_id(int $id) : mixed
Parameters
- $id : int
-
ID.
Tags
Return values
mixedset_locations()
Set locations.
public
set_locations([array $locations = array() ]) : mixed
Parameters
- $locations : array = array()
-
Array of locations.
Return values
mixedset_meta_data()
Set all meta data from array.
public
set_meta_data(array $data) : mixed
Parameters
- $data : array
-
Key/Value pairs.
Tags
Return values
mixedset_object_read()
Set object read property.
public
set_object_read([bool $read = true ]) : mixed
Parameters
- $read : bool = true
-
Should read?.
Tags
Return values
mixedset_props()
Set a collection of props in one go, collect any errors, and return the result.
public
set_props(array $props[, string $context = 'set' ]) : bool|WP_Error
Only sets using public methods.
Parameters
- $props : array
-
Key value pairs to set. Key is the prop and should map to a setter function name.
- $context : string = 'set'
-
In what context to run this.
Tags
Return values
bool|WP_Errorset_zone_locations()
Set zone locations.
public
set_zone_locations(array $locations) : mixed
Parameters
- $locations : array
-
Value to set.
Tags
Return values
mixedset_zone_name()
Set zone name.
public
set_zone_name(string $set) : mixed
Parameters
- $set : string
-
Value to set.
Return values
mixedset_zone_order()
Set zone order. Value to set.
public
set_zone_order(int $set) : mixed
Parameters
- $set : int
-
Value to set.
Return values
mixedupdate()
Update a zone.
public
update() : mixed
Tags
Return values
mixedupdate_meta_data()
Update meta data by key or ID, if provided.
public
update_meta_data(string $key, string|array $value, int $meta_id) : mixed
Parameters
- $key : string
-
Meta key.
- $value : string|array
-
Meta value.
- $meta_id : int
-
Meta ID.
Tags
Return values
mixederror()
When invalid data is found, throw an exception unless reading from the DB.
protected
error(string $code, string $message[, int $http_status_code = 400 ][, array $data = array() ]) : mixed
Parameters
- $code : string
-
Error code.
- $message : string
-
Error message.
- $http_status_code : int = 400
-
HTTP status code.
- $data : array = array()
-
Extra error data.
Tags
Return values
mixedfilter_null_meta()
Filter null meta values from array.
protected
filter_null_meta(mixed $meta) : bool
Parameters
- $meta : mixed
-
Meta value to check.
Tags
Return values
boolgenerate_zone_name()
Generate a zone name based on location.
protected
generate_zone_name() : string
Return values
stringget_hook_prefix()
Prefix for action and filter hooks on data.
protected
get_hook_prefix() : string
Tags
Return values
stringget_prop()
Gets a prop for a getter method.
protected
get_prop(string $prop[, string $context = 'view' ]) : mixed
Gets the value from either current pending changes, or the data itself. Context controls what happens to the value before it's returned.
Parameters
- $prop : string
-
Name of prop to get.
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
mixedis_internal_meta_key()
Check if the key is an internal one.
protected
is_internal_meta_key(string $key) : bool
Parameters
- $key : string
-
Key to check.
Tags
Return values
bool — true if it's an internal key, false otherwisemaybe_read_meta_data()
Read meta data if null.
protected
maybe_read_meta_data() : mixed
Tags
Return values
mixedset_date_prop()
Sets a date prop whilst handling formatting and datetime objects.
protected
set_date_prop(string $prop, string|int $value) : mixed
Parameters
- $prop : string
-
Name of prop to set.
- $value : string|int
-
Value of the prop.
Tags
Return values
mixedset_prop()
Sets a prop for a setter method.
protected
set_prop(string $prop, mixed $value) : mixed
This stores changes in a special array so we can track what needs saving the the DB later.
Parameters
- $prop : string
-
Name of prop to set.
- $value : mixed
-
Value of the prop.
Tags
Return values
mixedlocation_is_continent()
Location type detection.
private
location_is_continent(object $location) : bool
Parameters
- $location : object
-
Location to check.
Return values
boollocation_is_country()
Location type detection.
private
location_is_country(object $location) : bool
Parameters
- $location : object
-
Location to check.
Return values
boollocation_is_postcode()
Location type detection.
private
location_is_postcode(object $location) : bool
Parameters
- $location : object
-
Location to check.
Return values
boollocation_is_state()
Location type detection.
private
location_is_state(object $location) : bool
Parameters
- $location : object
-
Location to check.