@@ -105,17 +105,29 @@ function( $acc, $subscription_id ) {
105
105
$ subscription = \wcs_get_subscription ( $ subscription_id );
106
106
if ( $ subscription ->has_status ( WooCommerce_Connection::FORMER_SUBSCRIBER_STATUSES ) ) {
107
107
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
+ }
116
119
}
117
120
}
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 ) ) {
119
131
$ acc [] = $ subscription_id ;
120
132
}
121
133
}
0 commit comments