From 7832039bb7078d2d0711313fcbbfb31b53e9a5a4 Mon Sep 17 00:00:00 2001 From: Thiago Benvenuto Date: Thu, 3 Mar 2016 22:26:59 -0300 Subject: [PATCH 1/4] Implemented packages filter for marketplace --- includes/class-wc-shipping.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index 5a27c98aee7..9da86b55e7f 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -237,9 +237,19 @@ class WC_Shipping { return; } + // Allow packages to be reorganized before calculate the shipping + $packages = apply_filters( 'woocommerce_shipping_packages_before_calculate', $packages ); + // Calculate costs for passed packages foreach ( $packages as $package_key => $package ) { - $this->packages[ $package_key ] = $this->calculate_shipping_for_package( $package ); + $this->packages[ $package_key ] = $this->calculate_shipping_for_package( $package ); + } + + // Allow packages to be reorganized after calculate the shipping + $this->packages = apply_filters( 'woocommerce_shipping_packages_after_calculate', $this->packages ); + + if ( ! is_array( $this->packages ) || empty( $this->packages ) ) { + return; } // Get all chosen methods From 30a06d85dfc9bfdabcaa5dcc681c54e888d046c4 Mon Sep 17 00:00:00 2001 From: Thiago Benvenuto Date: Thu, 3 Mar 2016 22:49:35 -0300 Subject: [PATCH 2/4] Fixed identation mistake --- includes/class-wc-shipping.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index 9da86b55e7f..374ca079851 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -242,7 +242,7 @@ class WC_Shipping { // Calculate costs for passed packages foreach ( $packages as $package_key => $package ) { - $this->packages[ $package_key ] = $this->calculate_shipping_for_package( $package ); + $this->packages[ $package_key ] = $this->calculate_shipping_for_package( $package ); } // Allow packages to be reorganized after calculate the shipping From 180a09f52c9ce489034d5e13ffaebd1cef13ba4c Mon Sep 17 00:00:00 2001 From: Thiago Benvenuto Date: Tue, 15 Mar 2016 17:35:39 -0300 Subject: [PATCH 3/4] Added docblock to filter Removed duplicated filter Renamed filter after shipping costs are calculated --- includes/class-wc-shipping.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index 374ca079851..3b15ed6d011 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -237,16 +237,23 @@ class WC_Shipping { return; } - // Allow packages to be reorganized before calculate the shipping - $packages = apply_filters( 'woocommerce_shipping_packages_before_calculate', $packages ); - // Calculate costs for passed packages foreach ( $packages as $package_key => $package ) { $this->packages[ $package_key ] = $this->calculate_shipping_for_package( $package ); } - // Allow packages to be reorganized after calculate the shipping - $this->packages = apply_filters( 'woocommerce_shipping_packages_after_calculate', $this->packages ); + /** + * Allow packages to be reorganized after calculate 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.5.6 + * + * @param array $packages The array of packages after shipping costs are calculated. + */ + $this->packages = apply_filters( 'woocommerce_shipping_packages', $this->packages ); if ( ! is_array( $this->packages ) || empty( $this->packages ) ) { return; From 1847b0fab53697d945f93e32f28a096084765f8a Mon Sep 17 00:00:00 2001 From: Thiago Benvenuto Date: Tue, 15 Mar 2016 20:26:46 -0300 Subject: [PATCH 4/4] Adjusted since version --- includes/class-wc-shipping.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index 3b15ed6d011..b4b7f6cf750 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -249,7 +249,7 @@ class WC_Shipping { * 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.5.6 + * @since 2.6.0 * * @param array $packages The array of packages after shipping costs are calculated. */