From 4aa8554f1305396b1d701eb98060a3ae64d1b234 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Fri, 13 Dec 2024 14:35:33 -0500 Subject: [PATCH 1/2] Do not unset package contents for shipping subscriptions with free trials --- includes/class-wc-subscriptions-cart.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/includes/class-wc-subscriptions-cart.php b/includes/class-wc-subscriptions-cart.php index 93293032b..54eebf720 100644 --- a/includes/class-wc-subscriptions-cart.php +++ b/includes/class-wc-subscriptions-cart.php @@ -650,12 +650,6 @@ public static function set_cart_shipping_packages( $packages ) { if ( 'none' === self::$calculation_type ) { foreach ( $packages as $index => $package ) { - foreach ( $package['contents'] as $cart_item_key => $cart_item ) { - if ( WC_Subscriptions_Product::get_trial_length( $cart_item['data'] ) > 0 ) { - unset( $packages[ $index ]['contents'][ $cart_item_key ] ); - } - } - if ( empty( $packages[ $index ]['contents'] ) ) { unset( $packages[ $index ] ); } From c1999b8de7b1142719849012de031443360a308f Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 2 Jan 2025 20:45:42 -0500 Subject: [PATCH 2/2] Unset packages only when necessary --- includes/class-wc-subscriptions-cart.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/class-wc-subscriptions-cart.php b/includes/class-wc-subscriptions-cart.php index 54eebf720..a8ec01d7c 100644 --- a/includes/class-wc-subscriptions-cart.php +++ b/includes/class-wc-subscriptions-cart.php @@ -650,6 +650,12 @@ public static function set_cart_shipping_packages( $packages ) { if ( 'none' === self::$calculation_type ) { foreach ( $packages as $index => $package ) { + foreach ( $package['contents'] as $cart_item_key => $cart_item ) { + if ( WC_Subscriptions_Product::get_trial_length( $cart_item['data'] ) > 0 && apply_filters( 'wcs_unset_package_contents', '__return_true' ) ) { + unset( $packages[ $index ]['contents'][ $cart_item_key ] ); + } + } + if ( empty( $packages[ $index ]['contents'] ) ) { unset( $packages[ $index ] ); }