From a8471ad537b82fde6a5cb60198b478f0e7c9f24a Mon Sep 17 00:00:00 2001 From: dkoo Date: Thu, 28 Mar 2024 13:29:04 -0600 Subject: [PATCH] fix conflict between cancelled vs. next_payment dates for pending-cancel --- includes/class-wcs-importer.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/class-wcs-importer.php b/includes/class-wcs-importer.php index bbba06c..b97f0ec 100644 --- a/includes/class-wcs-importer.php +++ b/includes/class-wcs-importer.php @@ -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' ); }