Skip to content

Commit

Permalink
fix(esp-sync): get inactive subscriptions with failed or pending orde…
Browse files Browse the repository at this point in the history
…rs (#3658)

* fix(esp-sync): get inactive subscriptions with failed or pending orders

* fix: still only consider subscriptions that have at least one completed order

* refactor: pass a flat array for array_filter

* fix: on hold should add ex prefix to sync status

* refactor: break after finding any completed order

* perf: use WC_Subscription::get_payment_count() instead of fetching orders

* perf: just use wc_get_order()

---------

Co-authored-by: Leo Germani <[email protected]>
  • Loading branch information
dkoo and leogermani authored Jan 9, 2025
1 parent 40d4732 commit cca29d3
Showing 1 changed file with 12 additions and 3 deletions.
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

0 comments on commit cca29d3

Please sign in to comment.