@@ -683,29 +683,54 @@ public static function order_needs_payment( $needs_payment, $order, $valid_order
683
683
}
684
684
685
685
// Skip checks if order total is greater than zero, or
686
- // recurring total is zero, or
687
686
// order status isn't valid for payment.
688
- if ( $ order ->get_total () > 0 || self :: get_recurring_total ( $ order ) <= 0 || ! $ order ->has_status ( $ valid_order_statuses ) ) {
687
+ if ( $ order ->get_total () > 0 || ! $ order ->has_status ( $ valid_order_statuses ) ) {
689
688
return $ needs_payment ;
690
689
}
691
690
692
- // Check that there is at least 1 subscription with a next payment that would require a payment method.
693
- $ has_next_payment = false ;
691
+ // Skip checks if manual renewal is required.
692
+ if ( wcs_is_manual_renewal_required () ) {
693
+ return $ needs_payment ;
694
+ }
694
695
696
+ // Check if there's a subscription attached to this order that will require a payment method.
695
697
foreach ( wcs_get_subscriptions_for_order ( $ order ) as $ subscription ) {
698
+ $ has_next_payment = false ;
699
+ $ contains_expiring_limited_coupon = false ;
700
+ $ contains_free_trial = false ;
701
+ $ contains_synced = false ;
702
+
703
+ // Check if there's a subscription with a recurring total that would require a payment method.
704
+ $ recurring_total = (float ) $ subscription ->get_total ();
705
+
706
+ // Check that there is at least 1 subscription with a next payment that would require a payment method.
696
707
if ( $ subscription ->get_time ( 'next_payment ' ) ) {
697
708
$ has_next_payment = true ;
698
- break ;
699
709
}
700
- }
701
710
702
- if ( ! $ has_next_payment ) {
703
- return $ needs_payment ;
704
- }
711
+ // Check if there's a subscription with a limited recurring coupon that is expiring that would require a payment method after the coupon expires.
712
+ if ( class_exists ( 'WCS_Limited_Recurring_Coupon_Manager ' ) && WCS_Limited_Recurring_Coupon_Manager::order_has_limited_recurring_coupon ( $ subscription ) ) {
713
+ $ contains_expiring_limited_coupon = true ;
714
+ }
715
+
716
+ // Check if there's a subscription with a free trial that would require a payment method after the trial ends.
717
+ if ( $ subscription ->get_time ( 'trial_end ' ) ) {
718
+ $ contains_free_trial = true ;
719
+ }
705
720
706
- // If manual renewals are not required.
707
- if ( ! wcs_is_manual_renewal_required () ) {
708
- $ needs_payment = true ;
721
+ // Check if there's a subscription with a synced product that would require a payment method.
722
+ if ( WC_Subscriptions_Synchroniser::subscription_contains_synced_product ( $ subscription ) ) {
723
+ $ contains_synced = true ;
724
+ }
725
+
726
+ /**
727
+ * We need to collect a payment method if there's a subscription with a recurring total or a limited recurring coupon that is expiring and
728
+ * there's a next payment date or a free trial or a synced product.
729
+ */
730
+ if ( ( $ contains_expiring_limited_coupon || $ recurring_total > 0 ) && ( $ has_next_payment || $ contains_free_trial || $ contains_synced ) ) {
731
+ $ needs_payment = true ;
732
+ break ; // We've found a subscription that requires a payment method.
733
+ }
709
734
}
710
735
711
736
return $ needs_payment ;
0 commit comments