woocommerce_shipping_packages хук-фильтрWC 2.6.0

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.

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

add_filter( 'woocommerce_shipping_packages', 'wp_kama_woocommerce_shipping_packages_filter' );

/**
 * Function for `woocommerce_shipping_packages` filter-hook.
 * 
 * @param array $packages The array of packages after shipping costs are calculated.
 *
 * @return array
 */
function wp_kama_woocommerce_shipping_packages_filter( $packages ){

	// filter...
	return $packages;
}
$packages(массив)
The array of packages after shipping costs are calculated.

Список изменений

С версии 2.6.0 Введена.

Где вызывается хук

WC_Shipping::calculate_shipping()
woocommerce_shipping_packages
woocommerce/includes/class-wc-shipping.php 274
$this->packages = array_filter( (array) apply_filters( 'woocommerce_shipping_packages', $this->packages ) );

Где используется хук в WooCommerce

woocommerce/src/Blocks/Shipping/ShippingController.php 74
add_filter( 'woocommerce_shipping_packages', array( $this, 'filter_shipping_packages' ) );