WC_Shipping_Zones::get_zone_by() – Get shipping zone by an ID.

You appear to be a bot. Output may be restricted

Description

Get shipping zone by an ID.

Usage

$WC_Shipping_Zone|bool = WC_Shipping_Zones::get_zone_by( $by, $id );

Parameters

$by
( string ) optional default: zone_id – Get by 'zone_id' or 'instance_id'.
$id
( int ) optional – ID.

Returns

WC_Shipping_Zone|bool

Source

File name: woocommerce/includes/class-wc-shipping-zones.php
Lines:

1 to 23 of 23
  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;
  }
 

 View on GitHub View on Trac