WC_Shipping_Zones::get_shipping_method()public staticWC 2.6.0

Get shipping zone using it's ID.

Method of the class: WC_Shipping_Zones{}

No Hooks.

Return

true|false|WC_Shipping_Method.

Usage

$result = WC_Shipping_Zones::get_shipping_method( $instance_id );
$instance_id(int) (required)
Instance ID.

Changelog

Since 2.6.0 Introduced.

WC_Shipping_Zones::get_shipping_method() code WC 9.4.2

public static function get_shipping_method( $instance_id ) {
	$data_store          = WC_Data_Store::load( 'shipping-zone' );
	$raw_shipping_method = $data_store->get_method( $instance_id );
	$wc_shipping         = WC_Shipping::instance();
	$allowed_classes     = $wc_shipping->get_shipping_method_class_names();

	if ( ! empty( $raw_shipping_method ) && in_array( $raw_shipping_method->method_id, array_keys( $allowed_classes ), true ) ) {
		$class_name = $allowed_classes[ $raw_shipping_method->method_id ];
		if ( is_object( $class_name ) ) {
			$class_name = get_class( $class_name );
		}
		return new $class_name( $raw_shipping_method->instance_id );
	}
	return false;
}