Skip to content

Commit

Permalink
Merge pull request #3233 from dparker1005/profile-start-date-on-check…
Browse files Browse the repository at this point in the history
…out-level

Supporting setting profile start date on checkout level
  • Loading branch information
ideadude authored Jan 30, 2025
2 parents 55bfb7a + 9c321aa commit d56fdd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions classes/gateways/class.pmprogateway_stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,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.
Expand Down
13 changes: 10 additions & 3 deletions includes/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ function pmpro_calculate_profile_start_date( $order, $date_format, $filter = tru
// Get the checkout level.
$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 ) {
Expand All @@ -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.
Expand Down

0 comments on commit d56fdd6

Please sign in to comment.