Skip to content

Commit

Permalink
fix(esp-sync): sync non-donation subscription data even if no complet…
Browse files Browse the repository at this point in the history
…ed orders
  • Loading branch information
dkoo committed Jan 16, 2025
1 parent c1e03a4 commit 0bc8628
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions includes/reader-activation/sync/class-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,29 @@ function( $acc, $subscription_id ) {
$subscription = \wcs_get_subscription( $subscription_id );
if ( $subscription->has_status( WooCommerce_Connection::FORMER_SUBSCRIBER_STATUSES ) ) {

// 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;
// Only donation subscriptions that have at least one completed order are considered.
$is_donation = Donations::is_donation_order( $subscription );
$is_valid = $is_donation ? false : true;
if ( $is_donation ) {
$related_orders = $subscription->get_related_orders();
foreach ( $related_orders as $order_id ) {
$order = \wc_get_order( $order_id );
if ( $order->has_status( 'completed' ) ) {
$is_valid = true;
break;
}
}
}
if ( ! empty( $completed_order ) ) {

/**
* Filter to determine if a subscription with inactive status can be considered a contact's current product.
* Allows for customizing the sync behavior to include or exclude certain types of subscriptions.
*
* @param bool $is_valid If true, this subscription can be the contact's current product.
* @param WC_Subscription $subscription The subscription object.
*/
$is_valid = \apply_filters( 'newspack_reader_activation_inactive_subscription_is_valid', $is_valid, $subscription );
if ( ! empty( $is_valid ) ) {
$acc[] = $subscription_id;
}
}
Expand Down

0 comments on commit 0bc8628

Please sign in to comment.