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): sync non-donation subscription data even if no completed orders #3680

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading