diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index 8c9acfb1d8c..a803c400f2f 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -332,9 +332,26 @@ class WC_Shipping { if ( ! is_array( $stored_rates ) || $package_hash !== $stored_rates['package_hash'] || 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' ) ) { foreach ( $this->load_shipping_methods( $package ) as $shipping_method ) { if ( ! $shipping_method->supports( 'shipping-zones' ) || $shipping_method->get_instance_id() ) { - do_action( 'woocommerce_before_get_rates_for_package', $package, $shipping_method, $this ); - $package['rates'] = $package['rates'] + $shipping_method->get_rates_for_package( $package ); // + instead of array_merge maintains numeric keys - do_action( 'woocommerce_after_get_rates_for_package', $package, $shipping_method, $this ); + /** + * Fires before getting shipping rates for a package. + * + * @since 4.3.0 + * @param array $package Package of cart items. + * @param WC_Shipping_Method $shipping_method Shipping method instance. + */ + do_action( 'woocommerce_before_get_rates_for_package', $package, $shipping_method ); + + // Use + instead of array_merge to maintain numeric keys. + $package['rates'] = $package['rates'] + $shipping_method->get_rates_for_package( $package ); + + /** + * Fires after getting shipping rates for a package. + * + * @since 4.3.0 + * @param array $package Package of cart items. + * @param WC_Shipping_Method $shipping_method Shipping method instance. + */ + do_action( 'woocommerce_after_get_rates_for_package', $package, $shipping_method ); } }