Skip to content

Commit

Permalink
fix: check for billing period + interval, and account for in-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo committed Oct 23, 2024
1 parent 90c075b commit 6e5c96f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions includes/reader-revenue/woocommerce/class-woocommerce-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function fix_missing_next_payment_dates( $args, $assoc_args ) {
continue;
}

$result = [
$result = [
'ID' => $subscription->get_id(),
'status' => $subscription->get_status(),
'start_date' => $subscription_start,
Expand All @@ -230,10 +230,14 @@ public function fix_missing_next_payment_dates( $args, $assoc_args ) {
'missed_periods' => 0,
'missed_total' => 0,
];
$min_date = strtotime( $subscription_start );
while ( $min_date <= $now ) {
$result['missed_periods']++;
$min_date = strtotime( '+1 ' . $result['billing_period'], $min_date );
if ( ! empty( $result['billing_period'] ) && ! empty( $result['billing_interval'] ) ) {
$period = $result['billing_period'];
$interval = (int) $result['billing_interval'];
$min_date = strtotime( "+$interval $period", strtotime( $subscription_start ) ); // Start after first period so we don't count in-progress periods as missed.
while ( $min_date <= $now ) {
$result['missed_periods']++;
$min_date = strtotime( "+$interval $period", $min_date );
}
}

if ( $result['missed_periods'] ) {
Expand Down

0 comments on commit 6e5c96f

Please sign in to comment.