From acbbdfd8a7e1b030d2a34d0b4e93e3cc0e5e4be0 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Tue, 13 May 2025 10:27:04 +0100 Subject: [PATCH 1/2] Only call wcs_get_subscriptions_for_order() if order ID is > 0 --- ...ss-sv-wc-payment-gateway-integration-subscriptions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php b/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php index ade2f3ca7..38c12e28a 100644 --- a/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php +++ b/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php @@ -260,7 +260,9 @@ public function add_subscriptions_details_to_order( $order, $gateway ) { $order->payment->recurring = true; - $subscriptions = wcs_get_subscriptions_for_order( $order ); + // an order ID might be 0 if it's a mock order we use when adding a payment method + // passing in an order with an ID of 0 to `wcs_get_subscriptions_for_order()` can cause very unexpected results + $subscriptions = $order->get_id() > 0 ? wcs_get_subscriptions_for_order( $order ) : []; if ( ! empty( $subscriptions ) ) { @@ -278,7 +280,9 @@ public function add_subscriptions_details_to_order( $order, $gateway ) { $order->payment->recurring = true; - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order ); + // an order ID might be 0 if it's a mock order we use when adding a payment method + // passing in an order with an ID of 0 to `wcs_get_subscriptions_for_order()` can cause very unexpected results + $subscriptions = $order->get_id() > 0 ? wcs_get_subscriptions_for_order( $order ) : []; if ( ! empty( $subscriptions ) ) { From 5a9e97beeb1b64debd6cc4e954f047c1083416eb Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Tue, 13 May 2025 11:04:30 +0100 Subject: [PATCH 2/2] Correct function call --- .../class-sv-wc-payment-gateway-integration-subscriptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php b/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php index 38c12e28a..2ebd2b360 100644 --- a/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php +++ b/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php @@ -282,7 +282,7 @@ public function add_subscriptions_details_to_order( $order, $gateway ) { // an order ID might be 0 if it's a mock order we use when adding a payment method // passing in an order with an ID of 0 to `wcs_get_subscriptions_for_order()` can cause very unexpected results - $subscriptions = $order->get_id() > 0 ? wcs_get_subscriptions_for_order( $order ) : []; + $subscriptions = $order->get_id() > 0 ? wcs_get_subscriptions_for_renewal_order( $order ) : []; if ( ! empty( $subscriptions ) ) {