Skip to content

Commit 0e90669

Browse files
committed
Fix fatal error in subscription payment method switch in legacy checkout (#4222)
* ensure subscription and pre-order are not converted to Stripe order object in legacy experience * add changelog * remove whitespace * use the variables in condition
1 parent 25c08c2 commit 0e90669

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
* Update - Back button on the settings pages.
5858
* Update - Use individual product tax status instead of storewide tax setup when determining express checkout availability.
5959
* Fix - Ensure the subscription object is not converted into a Stripe order object.
60+
* Fix - Ensure the subscription and pre-order objects are not converted into a Stripe order object in legacy experience.
6061
* Update - Credit and Bank (BECS and ACSS) icons on the Block checkout page.
6162
* Fix - Fix BLIK visibility based on account and billing countries.
6263
* Add - Use Stripe Configuration API to manage payment methods enabled/disabled states.

includes/abstracts/abstract-wc-stripe-payment-gateway.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,16 +1053,26 @@ public function check_source( $prepared_source ) {
10531053
* @param stdClass $source Source information.
10541054
*/
10551055
public function save_source_to_order( $order, $source ) {
1056-
// Store source in the order.
1057-
$order = WC_Stripe_Order::to_instance( $order );
1058-
10591056
$customer_id = $source->customer ?? null;
10601057
$source_id = $source->source ?? null;
1061-
if ( $customer_id ) {
1062-
$order->set_stripe_customer_id( $customer_id );
1063-
}
1064-
if ( $source_id ) {
1065-
$order->set_source_id( $source_id );
1058+
1059+
if ( $this->is_subscription( $order ) || $this->has_pre_order( $order->get_id() ) ) {
1060+
if ( $customer_id ) {
1061+
$order->update_meta_data( '_stripe_customer_id', $customer_id );
1062+
}
1063+
1064+
if ( $source_id ) {
1065+
$order->update_meta_data( '_stripe_source_id', $source_id );
1066+
}
1067+
} else {
1068+
$order = WC_Stripe_Order::to_instance( $order );
1069+
1070+
if ( $customer_id ) {
1071+
$order->set_stripe_customer_id( $customer_id );
1072+
}
1073+
if ( $source_id ) {
1074+
$order->set_source_id( $source_id );
1075+
}
10661076
}
10671077

10681078
if ( is_callable( [ $order, 'save' ] ) ) {

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
167167
* Update - Back button on the settings pages.
168168
* Update - Use individual product tax status instead of storewide tax setup when determining express checkout availability.
169169
* Fix - Ensure the subscription object is not converted into a Stripe order object.
170+
* Fix - Ensure the subscription and pre-order objects are not converted into a Stripe order object in legacy experience.
170171
* Update - Credit and Bank (BECS and ACSS) icons on the Block checkout page.
171172
* Fix - Fix BLIK visibility based on account and billing countries.
172173
* Add - Use Stripe Configuration API to manage payment methods enabled/disabled states.

0 commit comments

Comments
 (0)