Only call wcs_get_subscriptions_for_order() if order ID is > 0 #772
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This updates our code to only call
wcs_get_subscriptions_for_order()if we have an order with a real ID.Story: MWC-18156
Release: #778 (release PR)
QA
Old FW version
I don't actually know how to reproduce the original issue, so we're just going to confirm behaviour matching with what we know.
masterbranch) and edit this file:woocommerce-gateway-authorize-net-cim/vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.phpadd_subscriptions_details_to_order()function definition (changed in this PR) and add logging right after we define$subscriptions.public function add_subscriptions_details_to_order( $order, $gateway ) { if ( isset( $order->payment ) ) { // defaults $order->payment->subscriptions = []; $order->payment->recurring = ! empty( $order->payment->recurring ) ?: false; // if the order contains a subscription (but is not a renewal) if ( wcs_order_contains_subscription( $order ) ) { $order->payment->recurring = true; $subscriptions = wcs_get_subscriptions_for_order( $order ); + error_log(sprintf('Order ID: %d; Number Subscriptions: %d', $order->get_id(), count($subscriptions))); if ( ! empty( $subscriptions ) ) { foreach ( $subscriptions as $subscription ) { if ( $subscription instanceof \WC_Subscription ) { $order->payment->subscriptions[] = $this->add_subscription_details_to_order( $subscription, false ); } } } // order is for a subscription renewal } elseif ( wcs_order_contains_renewal( $order ) ) { $order->payment->recurring = true; $subscriptions = wcs_get_subscriptions_for_renewal_order( $order ); + error_log(sprintf('Order ID: %d; Number Subscriptions: %d', $order->get_id(), count($subscriptions))); if ( ! empty( $subscriptions ) ) { foreach ( $subscriptions as $subscription ) { if ( $subscription instanceof \WC_Subscription ) { $order->payment->subscriptions[] = $this->add_subscription_details_to_order( $subscription, true ); } } } } } return $order; }Order ID: 1114; Number Subscriptions: 1)New FW version
composer installwoocommerce-gateway-authorize-net-cim/vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.phperror_log(sprintf('Order ID: %d; Number Subscriptions: %d', $order->get_id(), count($subscriptions)));in placeBefore merge