WC_Shipping_Zones::get_zone_by( string $by = 'zone_id', int $id )
Get shipping zone by an ID.
Description Description
Parameters Parameters
- $by
-
(Optional) Get by 'zone_id' or 'instance_id'.
Default value: 'zone_id'
- $id
-
(Required) ID.
Return Return
(WC_Shipping_Zone|bool)
Source Source
File: includes/class-wc-shipping-zones.php
public static function get_zone_by( $by = 'zone_id', $id = 0 ) {
$zone_id = false;
switch ( $by ) {
case 'zone_id':
$zone_id = $id;
break;
case 'instance_id':
$data_store = WC_Data_Store::load( 'shipping-zone' );
$zone_id = $data_store->get_zone_id_by_instance_id( $id );
break;
}
if ( false !== $zone_id ) {
try {
return new WC_Shipping_Zone( $zone_id );
} catch ( Exception $e ) {
return false;
}
}
return false;
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.6.0 | Introduced. |