@@ -845,8 +845,10 @@ private function create_mandate_options_for_order( $order, $subscriptions ) {
845
845
846
846
$ sub_amount = 0 ;
847
847
848
+ $ cart_contain_switches = WC_Subscriptions_Switcher::cart_contains_switches ();
849
+ $ is_changing_payment_method = $ this ->is_changing_payment_method_for_subscription ();
850
+
848
851
// If this is a switch order we set the mandate options based on the new subscription.
849
- $ cart_contain_switches = WC_Subscriptions_Switcher::cart_contains_switches ();
850
852
if ( $ cart_contain_switches ) {
851
853
foreach ( WC ()->cart ->cart_contents as $ cart_item ) {
852
854
$ subscription_price = WC_Subscriptions_Product::get_price ( $ cart_item ['data ' ] );
@@ -858,6 +860,13 @@ private function create_mandate_options_for_order( $order, $subscriptions ) {
858
860
859
861
$ sub_billing_period = WC_Subscriptions_Product::get_period ( $ cart_item ['data ' ] );
860
862
$ sub_billing_interval = absint ( WC_Subscriptions_Product::get_interval ( $ cart_item ['data ' ] ) );
863
+ } elseif ( $ is_changing_payment_method ) {
864
+ // On the change payment method page, the $order object sent in this function is actually a subscription.
865
+ $ subscription = $ order ;
866
+
867
+ $ sub_amount = WC_Stripe_Helper::get_stripe_amount ( $ subscription ->get_subtotal (), $ currency );
868
+ $ sub_billing_period = strtolower ( $ subscription ->get_billing_period () );
869
+ $ sub_billing_interval = $ subscription ->get_billing_interval ();
861
870
} else {
862
871
// If this is the first order, not a renewal, then get the subscriptions for the parent order.
863
872
if ( empty ( $ subscriptions ) ) {
@@ -887,7 +896,7 @@ private function create_mandate_options_for_order( $order, $subscriptions ) {
887
896
}
888
897
889
898
$ has_interval = $ sub_billing_period && $ sub_billing_interval > 0 ;
890
- if ( $ has_interval && ( 1 === count ( $ subscriptions ) || $ cart_contain_switches ) ) {
899
+ if ( $ has_interval && ( 1 === count ( $ subscriptions ) || $ cart_contain_switches || $ is_changing_payment_method ) ) {
891
900
$ mandate_options ['amount_type ' ] = 'fixed ' ;
892
901
$ mandate_options ['interval ' ] = $ sub_billing_period ;
893
902
$ mandate_options ['interval_count ' ] = $ sub_billing_interval ;
0 commit comments