Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 860a9f7

Browse files
authored
Merge branch 'trunk' into issue/4702-update-modified-date-on-related-order-creation
2 parents 0f9af31 + 578bcfb commit 860a9f7

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Fix - Label improvements on subscription and order page templates.
1010
* Fix - Fixed an issue with subscriptions containing multiple renewal orders to mark a random item as processing, instead of the last order.
1111
* Fix - Prevent errors from invalid subscription objects during customer payment method updates.
12+
* Fix - Resolved an error when purchasing subscription products on the block checkout with a limited recurring coupon.
1213

1314
= 7.2.0 - 2024-06-13 =
1415
* Fix - label improvement on my subscription page template.

includes/class-wc-subscriptions-order.php

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -683,29 +683,54 @@ public static function order_needs_payment( $needs_payment, $order, $valid_order
683683
}
684684

685685
// Skip checks if order total is greater than zero, or
686-
// recurring total is zero, or
687686
// 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 ) ) {
689688
return $needs_payment;
690689
}
691690

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+
}
694695

696+
// Check if there's a subscription attached to this order that will require a payment method.
695697
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.
696707
if ( $subscription->get_time( 'next_payment' ) ) {
697708
$has_next_payment = true;
698-
break;
699709
}
700-
}
701710

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+
}
705720

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+
}
709734
}
710735

711736
return $needs_payment;

0 commit comments

Comments
 (0)