WC_Shipping::calculate_shipping()publicWC 1.0

Calculate shipping for (multiple) packages of cart items.

Метод класса: WC_Shipping{}

Хуки из метода

Возвращает

Массив. Array of calculated packages.

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

$WC_Shipping = new WC_Shipping();
$WC_Shipping->calculate_shipping( $packages );
$packages(массив)
multi-dimensional array of cart items to calc shipping for.
По умолчанию: array()

Код WC_Shipping::calculate_shipping() WC 8.7.0

public function calculate_shipping( $packages = array() ) {
	$this->packages = array();

	if ( ! $this->enabled || empty( $packages ) ) {
		return array();
	}

	// Calculate costs for passed packages.
	foreach ( $packages as $package_key => $package ) {
		$this->packages[ $package_key ] = $this->calculate_shipping_for_package( $package, $package_key );
	}

	/**
	 * Allow packages to be reorganized after calculating the shipping.
	 *
	 * This filter can be used to apply some extra manipulation after the shipping costs are calculated for the packages
	 * but before WooCommerce does anything with them. A good example of usage is to merge the shipping methods for multiple
	 * packages for marketplaces.
	 *
	 * @since 2.6.0
	 *
	 * @param array $packages The array of packages after shipping costs are calculated.
	 */
	$this->packages = array_filter( (array) apply_filters( 'woocommerce_shipping_packages', $this->packages ) );

	return $this->packages;
}