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(esp-sync): get inactive subscriptions with failed or pending orders #3658

Merged
merged 7 commits into from
Jan 9, 2025
15 changes: 12 additions & 3 deletions includes/reader-activation/sync/class-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,17 @@ function( $acc, $subscription_id ) {
$subscription = \wcs_get_subscription( $subscription_id );
if ( $subscription->has_status( WooCommerce_Connection::FORMER_SUBSCRIBER_STATUSES ) ) {

// Only subscriptions that had a completed order are considered.
if ( ! empty( $subscription->get_date( 'last_order_date_completed' ) ) ) {
// Only subscriptions that have at least one completed order are considered.
$related_orders = $subscription->get_related_orders();
$completed_order = false;
foreach ( $related_orders as $order_id ) {
$order = \wc_get_order( $order_id );
if ( $order->has_status( 'completed' ) ) {
$completed_order = $order_id;
break;
}
}
if ( ! empty( $completed_order ) ) {
$acc[] = $subscription_id;
}
}
Expand Down Expand Up @@ -257,7 +266,7 @@ private static function get_order_metadata( $order, $payment_page_url = false )
}

// If the subscription has moved to a cancelled or expired status.
if ( $current_subscription->has_status( [ 'cancelled', 'expired' ] ) ) {
if ( $current_subscription->has_status( [ 'cancelled', 'expired', 'on-hold' ] ) ) {
$donor_status = 'Ex-' . $donor_status;
}
$metadata['membership_status'] = $donor_status;
Expand Down
Loading