WordPress at Your Fingertips
function is not described

WC_Shipping_Zones::get_zone_by() public WC 2.6.0

Get shipping zone by an ID.

{} It's a method of the class: WC_Shipping_Zones{}

No Hooks.

Return

WC_Shipping_Zone|true|false.

Usage

$result = WC_Shipping_Zones::get_zone_by( $by, $id );
$by(string)
Get by 'zone_id' or 'instance_id'.
Default: 'zone_id'
$id(int)
ID.

Changelog

Since 2.6.0 Introduced.

Code of WC_Shipping_Zones::get_zone_by() WC 5.6.0

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;
}