WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Schemas

CartShippingRateSchema::prepare_package_shipping_rates_response() protected WC 1.0

Prepare an array of rates from a package for the response.

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

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_package_shipping_rates_response( $package );
$package(array) (required)
Shipping package complete with rates from WooCommerce.

Code of CartShippingRateSchema::prepare_package_shipping_rates_response() WC 5.7.1

protected function prepare_package_shipping_rates_response( $package ) {
	$rates          = $package['rates'];
	$selected_rates = wc()->session->get( 'chosen_shipping_methods', array() );
	$selected_rate  = isset( $selected_rates[ $package['package_id'] ] ) ? $selected_rates[ $package['package_id'] ] : '';

	if ( empty( $selected_rate ) && ! empty( $package['rates'] ) ) {
		$selected_rate = wc_get_chosen_shipping_method_for_package( $package['package_id'], $package );
	}

	$response = [];

	foreach ( $package['rates'] as $rate ) {
		$response[] = $this->get_rate_response( $rate, $selected_rate );
	}

	return $response;
}