PHP Class WC_Shipping_Zone

Controls a single zone, loads shipping methods, and registers them for use.
Show file Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$data array Zone Data
$id integer | null Zone ID

Public Methods

Method Description
__construct ( integer | object $zone = null ) Constructor for zones.
add_location ( string $code, string $type ) Add location (state or postcode) to a zone.
add_shipping_method ( string $type ) : integer Add a shipping method to this zone.
clear_locations ( array | string $types = ['postcode', 'state', 'country', 'continent'] ) Clear all locations for this zone.
delete_shipping_method ( integer $instance_id ) : True Delete a shipping method from a zone.
get_formatted_location ( integer $max = 10, string $context = 'view' ) : string Return a text string representing what this zone is for.
get_shipping_methods ( $enabled_only = false ) : array Get shipping methods linked to this zone.
get_zone_locations ( string $context = 'view' ) : array Get zone locations.
get_zone_name ( string $context = 'view' ) : string Get zone name.
get_zone_order ( string $context = 'view' ) : integer Get zone order.
is_valid_location_type ( string $type ) : boolean Is passed location type valid?
save ( ) : integer Save zone data to the database.
set_locations ( array $locations = [] ) Set locations.
set_zone_locations ( $locations ) Set zone locations.
set_zone_name ( string $set ) Set zone name.
set_zone_order ( integer $set ) Set zone order.

Protected Methods

Method Description
generate_zone_name ( ) : string Generate a zone name based on location.
get_hook_prefix ( ) : string Prefix for action and filter hooks on data.

Private Methods

Method Description
location_is_continent ( object $location ) : boolean Location type detection.
location_is_country ( object $location ) : boolean Location type detection.
location_is_postcode ( object $location ) : boolean Location type detection.
location_is_state ( object $location ) : boolean Location type detection.

Method Details

__construct() public method

Constructor for zones.
public __construct ( integer | object $zone = null )
$zone integer | object Zone ID to load from the DB or zone object.

add_location() public method

Add location (state or postcode) to a zone.
public add_location ( string $code, string $type )
$code string
$type string state or postcode

add_shipping_method() public method

Add a shipping method to this zone.
public add_shipping_method ( string $type ) : integer
$type string shipping method type
return integer new instance_id, 0 on failure

clear_locations() public method

Clear all locations for this zone.
public clear_locations ( array | string $types = ['postcode', 'state', 'country', 'continent'] )
$types array | string of location to clear

delete_shipping_method() public method

Delete a shipping method from a zone.
public delete_shipping_method ( integer $instance_id ) : True
$instance_id integer
return True on success, false on failure

generate_zone_name() protected method

Generate a zone name based on location.
protected generate_zone_name ( ) : string
return string

get_formatted_location() public method

Return a text string representing what this zone is for.
public get_formatted_location ( integer $max = 10, string $context = 'view' ) : string
$max integer
$context string
return string

get_hook_prefix() protected method

Prefix for action and filter hooks on data.
Since: 2.7.0
protected get_hook_prefix ( ) : string
return string

get_shipping_methods() public method

Get shipping methods linked to this zone.
public get_shipping_methods ( $enabled_only = false ) : array
return array of objects

get_zone_locations() public method

Get zone locations.
public get_zone_locations ( string $context = 'view' ) : array
$context string
return array of zone objects

get_zone_name() public method

Get zone name.
public get_zone_name ( string $context = 'view' ) : string
$context string
return string

get_zone_order() public method

Get zone order.
public get_zone_order ( string $context = 'view' ) : integer
$context string
return integer

is_valid_location_type() public method

Is passed location type valid?
public is_valid_location_type ( string $type ) : boolean
$type string
return boolean

save() public method

Save zone data to the database.
public save ( ) : integer
return integer

set_locations() public method

Set locations.
public set_locations ( array $locations = [] )
$locations array Array of locations

set_zone_locations() public method

Set zone locations.
Since: 2.7.0
public set_zone_locations ( $locations )

set_zone_name() public method

Set zone name.
public set_zone_name ( string $set )
$set string

set_zone_order() public method

Set zone order.
public set_zone_order ( integer $set )
$set integer

Property Details

$data protected property

Zone Data
protected array $data
return array

$id protected property

Zone ID
protected int|null $id
return integer | null