WC_Shipping::calculate_shipping( array $packages = array() )
Calculate shipping for (multiple) packages of cart items.
Description Description
Parameters Parameters
- $packages
-
(Optional) multi-dimensional array of cart items to calc shipping for.
Default value: array()
Return Return
(array) Array of calculated packages.
Source Source
File: includes/class-wc-shipping.php
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;
}