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.


Top ↑

Return Return

(WC_Shipping_Zone|bool)


Top ↑

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

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.