WordPress at Your Fingertips
function is not described

WC_Gateway_COD::get_canonical_package_rate_ids() private WC 3.4.0

Converts the chosen rate IDs generated by Shipping Methods to a canonical 'method_id:instance_id' format.

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

No Hooks.

Return

Array. $canonical_rate_ids Rate IDs in a canonical format.

Usage

// private - for code of main (parent) class only
$result = $this->get_canonical_package_rate_ids( $chosen_package_rate_ids );
$chosen_package_rate_ids(array) (required)
Rate IDs as generated by shipping methods. Can be anything if a shipping method doesn't honor WC conventions.

Changelog

Since 3.4.0 Introduced.

Code of WC_Gateway_COD::get_canonical_package_rate_ids() WC 5.6.0

private function get_canonical_package_rate_ids( $chosen_package_rate_ids ) {

	$shipping_packages  = WC()->shipping()->get_packages();
	$canonical_rate_ids = array();

	if ( ! empty( $chosen_package_rate_ids ) && is_array( $chosen_package_rate_ids ) ) {
		foreach ( $chosen_package_rate_ids as $package_key => $chosen_package_rate_id ) {
			if ( ! empty( $shipping_packages[ $package_key ]['rates'][ $chosen_package_rate_id ] ) ) {
				$chosen_rate          = $shipping_packages[ $package_key ]['rates'][ $chosen_package_rate_id ];
				$canonical_rate_ids[] = $chosen_rate->get_method_id() . ':' . $chosen_rate->get_instance_id();
			}
		}
	}

	return $canonical_rate_ids;
}