WordPress at Your Fingertips
function is not described

WC_Shipping::calculate_shipping() public WC 1.0

Calculate shipping for (multiple) packages of cart items.

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

Hooks from the method

Return

Array. Array of calculated packages.

Usage

$WC_Shipping = new WC_Shipping();
$WC_Shipping->calculate_shipping( $packages );
$packages(array)
multi-dimensional array of cart items to calc shipping for.
Default: array()

Code of WC_Shipping::calculate_shipping() WC 5.9.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;
}