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

fix conflict between cancelled vs. next_payment dates for pending-cancel #283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions includes/class-wcs-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,18 @@ public static function import_subscription( $data ) {
}
}

// make the sure end of prepaid term exists for subscription that are about to be set to pending-cancellation - continue to use the next payment date if that exists
if ( 'pending-cancel' == $status && ( empty( $dates_to_update['next_payment_date'] ) || strtotime( $dates_to_update['next_payment_date'] ) < current_time( 'timestamp', true ) ) ) {
// ensure pending-cancellation subscriptions have an end date in the future.
if ( 'pending-cancel' == $status ) {
if ( empty( $dates_to_update['end_date'] ) || strtotime( $dates_to_update['end_date'] ) < current_time( 'timestamp', true ) ) {
// next payment date becomes the end date.
if ( ! empty( $dates_to_update['next_payment_date'] ) && strtotime( $dates_to_update['next_payment_date'] ) > current_time( 'timestamp', true ) ) {
$dates_to_update['end_date'] = $dates_to_update['next_payment_date'];
}
}

if ( ! empty( $dates_to_update['end_date'] ) && strtotime( $dates_to_update['end_date'] ) > current_time( 'timestamp', true ) ) {
$dates_to_update['next_payment_date'] = $dates_to_update['end_date'];
unset( $dates_to_update['end_date'] );
// pending-cancellation subs cannot have a next_payment date if they also have a cancelled date.
unset( $dates_to_update['next_payment_date'] );
} else {
$result['error'][] = __( 'Importing a pending cancelled subscription requires an end date in the future.', 'wcs-import-export' );
}
Expand Down