From 633a58c65e47edae998f7064b95d9bdf6296d7b0 Mon Sep 17 00:00:00 2001 From: David Parker Date: Mon, 16 Dec 2024 13:25:58 -0500 Subject: [PATCH 1/3] Supporting setting profile start date on checkout level --- includes/checkout.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/checkout.php b/includes/checkout.php index f5c03f1fb..4875b5dc8 100644 --- a/includes/checkout.php +++ b/includes/checkout.php @@ -13,10 +13,16 @@ */ function pmpro_calculate_profile_start_date( $order, $date_format, $filter = true ) { // Get the checkout level. - $level = $order->getMembershipLevelAtCheckout(); + $level = $order->getMembershipLevelAtCheckout(); - // Calculate the profile start date. - $profile_start_date = date_i18n( 'Y-m-d H:i:s', strtotime( '+ ' . $level->cycle_number . ' ' . $level->cycle_period ) ); + // If the level already has a profile start date set, use it. Otherwise, calculate it based on the cycle number and period. + if ( ! empty( $level->profile_start_date ) ) { + // Use the profile start date that is already set. + $profile_start_date = date_i18n( 'Y-m-d H:i:s', strtotime( $level->profile_start_date ) ); + } else { + // Calculate the profile start date based on the cycle number and period. + $profile_start_date = date_i18n( 'Y-m-d H:i:s', strtotime( '+ ' . $level->cycle_number . ' ' . $level->cycle_period ) ); + } // Filter the profile start date if needed. if ( $filter ) { @@ -28,13 +34,14 @@ function pmpro_calculate_profile_start_date( $order, $date_format, $filter = tru * to use that format in case we update this code in the future. * * @since 1.4 + * @deprecated TBD Set the 'profile_start_date' property on the checkout level object instead. * * @param string $profile_start_date The profile start date in UTC YYYY-MM-DD HH:MM:SS format. * @param MemberOrder $order The order that the profile start date is being calculated for. * * @return string The profile start date in UTC YYYY-MM-DD HH:MM:SS format. */ - $profile_start_date = apply_filters( 'pmpro_profile_start_date', $profile_start_date, $order ); + $profile_start_date = apply_filters_deprecated( 'pmpro_profile_start_date', array( $profile_start_date, $order ), 'TBD' ); } // Convert $profile_start_date to correct format. From 2bbbe3d84ed2092d8d688cb382e1fee24d62ab6d Mon Sep 17 00:00:00 2001 From: David Parker Date: Mon, 16 Dec 2024 13:32:13 -0500 Subject: [PATCH 2/3] Whitespace --- includes/checkout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/checkout.php b/includes/checkout.php index 4875b5dc8..e2dc93c25 100644 --- a/includes/checkout.php +++ b/includes/checkout.php @@ -13,7 +13,7 @@ */ function pmpro_calculate_profile_start_date( $order, $date_format, $filter = true ) { // Get the checkout level. - $level = $order->getMembershipLevelAtCheckout(); + $level = $order->getMembershipLevelAtCheckout(); // If the level already has a profile start date set, use it. Otherwise, calculate it based on the cycle number and period. if ( ! empty( $level->profile_start_date ) ) { From 9c321aa8abb48ddb4b5cc10e41df54a3dce1222c Mon Sep 17 00:00:00 2001 From: David Parker Date: Mon, 16 Dec 2024 13:50:50 -0500 Subject: [PATCH 3/3] Fixing "combine payments" logic for profile_start_date on checkout level obj --- classes/gateways/class.pmprogateway_stripe.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/gateways/class.pmprogateway_stripe.php b/classes/gateways/class.pmprogateway_stripe.php index fcccbd5e2..bab2718de 100644 --- a/classes/gateways/class.pmprogateway_stripe.php +++ b/classes/gateways/class.pmprogateway_stripe.php @@ -1611,6 +1611,7 @@ static function pmpro_checkout_before_change_membership_level( $user_id, $morder if ( empty( $level->trial_limit ) && // Check if there is a trial period. $filtered_trial_period_days === $unfiltered_trial_period_days && // Check if the trial period is the same as the filtered trial period. + empty( $level->profile_start_date ) && // Check if the profile start date set directly on the level is empty. ( ! empty( $initial_payment_amount ) && $initial_payment_amount === $recurring_payment_amount ) // Check if the initial payment and recurring payment prices are the same. ) { // We can combine the initial payment and the recurring payment.