WC_Cart::get_chosen_shipping_methods()protectedWC 3.2.0

Given a set of packages with rates, get the chosen ones only.

Method of the class: WC_Cart{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_chosen_shipping_methods( $calculated_shipping_packages );
$calculated_shipping_packages(array)
Array of packages.
Default: array()

Changelog

Since 3.2.0 Introduced.

WC_Cart::get_chosen_shipping_methods() code WC 8.6.1

protected function get_chosen_shipping_methods( $calculated_shipping_packages = array() ) {
	$chosen_methods = array();
	// Get chosen methods for each package to get our totals.
	foreach ( $calculated_shipping_packages as $key => $package ) {
		$chosen_method = wc_get_chosen_shipping_method_for_package( $key, $package );
		if ( $chosen_method ) {
			$chosen_methods[ $key ] = $package['rates'][ $chosen_method ];
		}
	}
	return $chosen_methods;
}