Skip to content

Commit dd0898f

Browse files
authored
fix(esp-sync): sync non-donation subscription data even if no completed orders (#3680)
1 parent c1e03a4 commit dd0898f

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

includes/reader-activation/sync/class-woocommerce.php

+21-9
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,29 @@ function( $acc, $subscription_id ) {
105105
$subscription = \wcs_get_subscription( $subscription_id );
106106
if ( $subscription->has_status( WooCommerce_Connection::FORMER_SUBSCRIBER_STATUSES ) ) {
107107

108-
// Only subscriptions that have at least one completed order are considered.
109-
$related_orders = $subscription->get_related_orders();
110-
$completed_order = false;
111-
foreach ( $related_orders as $order_id ) {
112-
$order = \wc_get_order( $order_id );
113-
if ( $order->has_status( 'completed' ) ) {
114-
$completed_order = $order_id;
115-
break;
108+
// Only donation subscriptions that have at least one completed order are considered.
109+
$is_donation = Donations::is_donation_order( $subscription );
110+
$is_valid = $is_donation ? false : true;
111+
if ( $is_donation ) {
112+
$related_orders = $subscription->get_related_orders();
113+
foreach ( $related_orders as $order_id ) {
114+
$order = \wc_get_order( $order_id );
115+
if ( $order->has_status( 'completed' ) ) {
116+
$is_valid = true;
117+
break;
118+
}
116119
}
117120
}
118-
if ( ! empty( $completed_order ) ) {
121+
122+
/**
123+
* Filter to determine if a subscription with inactive status can be considered a contact's current product.
124+
* Allows for customizing the sync behavior to include or exclude certain types of subscriptions.
125+
*
126+
* @param bool $is_valid If true, this subscription can be the contact's current product.
127+
* @param WC_Subscription $subscription The subscription object.
128+
*/
129+
$is_valid = \apply_filters( 'newspack_reader_activation_inactive_subscription_is_valid', $is_valid, $subscription );
130+
if ( ! empty( $is_valid ) ) {
119131
$acc[] = $subscription_id;
120132
}
121133
}

0 commit comments

Comments
 (0)