Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting setting profile start date on checkout level #3233

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions classes/gateways/class.pmprogateway_stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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