Skip to content

Commit

Permalink
Merge pull request woocommerce#26542 from woocommerce/tweak/add-shipp…
Browse files Browse the repository at this point in the history
…ing-actions

Add actions before/after shipping calculation
  • Loading branch information
claudiosanches authored Jun 3, 2020
2 parents bf042a4 + 855b1d3 commit 3701f0a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion includes/class-wc-shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,26 @@ public function calculate_shipping_for_package( $package = array(), $package_key
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() ) {
$package['rates'] = $package['rates'] + $shipping_method->get_rates_for_package( $package ); // + instead of array_merge maintains numeric keys
/**
* 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 );
}
}

Expand Down

0 comments on commit 3701f0a

Please sign in to comment.