Created
January 13, 2021 10:39
-
-
Save tharsheblows/7afd3e01bb5d30e2dcff835e000e84ef to your computer and use it in GitHub Desktop.
Allow users to resubscribe to cancelled parent subscriptions which have only cancelled resubscription orders. (Based on WooCommerce 3.0.11)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/includes/wcs-resubscribe-functions.php b/includes/wcs-resubscribe-functions.php | |
index 2faea23..b8e94c8 100644 | |
--- a/includes/wcs-resubscribe-functions.php | |
+++ b/includes/wcs-resubscribe-functions.php | |
@@ -219,11 +219,23 @@ function wcs_can_user_resubscribe_to( $subscription, $user_id = '' ) { | |
} | |
} | |
- if ( empty( $resubscribe_order_ids ) && $subscription->get_payment_count() > 0 && true === $all_line_items_exist && false === $has_active_limited_subscription ) { | |
+ // When an order is cancelled, the subscription is cancelled. | |
+ // If all the resubscribe orders have payment cancelled and all the subscriptions have a status of cancelled then the user can resubscribe. | |
+ $resubscribe_order_cancelled = true; | |
+ foreach ( $resubscribe_order_ids as $resubscribe_order_id ) { | |
+ $resubscribe_order = wc_get_order( $resubscribe_order_id ); | |
+ if ( ! $resubscribe_order->has_status( 'cancelled' ) ) { | |
+ $resubscribe_order_cancelled = false; | |
+ break; | |
+ } | |
+ } | |
+ | |
+ if ( ( empty( $resubscribe_order_ids ) || $resubscribe_order_cancelled === true ) && $subscription->get_payment_count() > 0 && true === $all_line_items_exist && false === $has_active_limited_subscription ) { | |
$can_user_resubscribe = true; | |
} else { | |
$can_user_resubscribe = false; | |
} | |
+ | |
} | |
return apply_filters( 'wcs_can_user_resubscribe_to_subscription', $can_user_resubscribe, $subscription, $user_id ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This diff is not quite correct and requires a check on that $resubscribe_order is indeed a WC_Order object before checking the status. See a slightly longer explanation here.