Automattic\WooCommerce\StoreApi\Utilities

CartController::get_shipping_packages()publicWC 1.0

Get shipping packages from the cart with calculated shipping rates.

{} Это метод класса: CartController{}

Хуков нет.

Возвращает

Массив.

Использование

$CartController = new CartController();
$CartController->get_shipping_packages( $calculate_rates );
$calculate_rates(true|false)
Should rates for the packages also be returned.
По умолчанию: true

Код CartController::get_shipping_packages() WC 7.1.0

public function get_shipping_packages( $calculate_rates = true ) {
	$cart = $this->get_cart_instance();

	// See if we need to calculate anything.
	if ( ! $cart->needs_shipping() ) {
		return [];
	}

	if ( Package::feature()->is_experimental_build() ) {
		// This is a temporary measure until we can bring such change to WooCommerce core.
		add_filter( 'woocommerce_get_shipping_methods', [ $this, 'enable_local_pickup_without_address' ] );
	}

	$packages = $cart->get_shipping_packages();

	// Add extra package data to array.
	if ( count( $packages ) ) {
		$packages = array_map(
			function( $key, $package, $index ) {
				$package['package_id']   = isset( $package['package_id'] ) ? $package['package_id'] : $key;
				$package['package_name'] = isset( $package['package_name'] ) ? $package['package_name'] : $this->get_package_name( $package, $index );
				return $package;
			},
			array_keys( $packages ),
			$packages,
			range( 1, count( $packages ) )
		);
	}

	$packages = $calculate_rates ? wc()->shipping()->calculate_shipping( $packages ) : $packages;

	if ( Package::feature()->is_experimental_build() ) {
		// This is a temporary measure until we can bring such change to WooCommerce core.
		remove_filter( 'woocommerce_get_shipping_methods', [ $this, 'enable_local_pickup_without_address' ] );
	}

	return $packages;
}