Skip to content

Commit bcd4103

Browse files
Only call wcs_get_subscriptions_for_order() if order ID is > 0 (#772)
* Only call wcs_get_subscriptions_for_order() if order ID is > 0 * Correct function call
1 parent 7edcca7 commit bcd4103

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ public function add_subscriptions_details_to_order( $order, $gateway ) {
260260

261261
$order->payment->recurring = true;
262262

263-
$subscriptions = wcs_get_subscriptions_for_order( $order );
263+
// an order ID might be 0 if it's a mock order we use when adding a payment method
264+
// passing in an order with an ID of 0 to `wcs_get_subscriptions_for_order()` can cause very unexpected results
265+
$subscriptions = $order->get_id() > 0 ? wcs_get_subscriptions_for_order( $order ) : [];
264266

265267
if ( ! empty( $subscriptions ) ) {
266268

@@ -278,7 +280,9 @@ public function add_subscriptions_details_to_order( $order, $gateway ) {
278280

279281
$order->payment->recurring = true;
280282

281-
$subscriptions = wcs_get_subscriptions_for_renewal_order( $order );
283+
// an order ID might be 0 if it's a mock order we use when adding a payment method
284+
// passing in an order with an ID of 0 to `wcs_get_subscriptions_for_order()` can cause very unexpected results
285+
$subscriptions = $order->get_id() > 0 ? wcs_get_subscriptions_for_renewal_order( $order ) : [];
282286

283287
if ( ! empty( $subscriptions ) ) {
284288

0 commit comments

Comments
 (0)