Closed kaushikasomaiya closed 9 months ago
Hey @kaushikasomaiya
I suspect your theory is correct. What is happening is some code is running between us creating the order and adding the line items, that code calls $order->needs_processing()
and it sets the transient to 0 before we've added the items.
The question I then have is why is WooCommerce core not deleting that transient when we add the line items?
Well looking at that, WC only deletes the transient when $order->add_product()
and $order->save_items()
is called. When we copy line items to renewal orders, neither of those functions are called.
We use wc_add_order_item()
. For some reason WC don't delete the transient in that function.
I think there are two approaches we can take to this.
wc_add_order_item()
deletes the transient given its similar to $order->add_product()
.'I'm going to discuss with core folks about how we should tackle this.
In 7083560-zen,
The following note was found on affected renewal orders:
Full Size: https://d.pr/i/OZLDQ8
6684693-zen 7027840-zen
I don't know if this helps
09-18-2023 @ 21:50:26 - hook name: woocommerce_before_order_object_save
09-18-2023 @ 21:50:26 - pending
09-18-2023 @ 21:50:26 - hook name: woocommerce_payment_complete_order_status
09-18-2023 @ 21:50:26 - pending
09-18-2023 @ 21:50:26 - hook name: woocommerce_before_order_object_save
09-18-2023 @ 21:50:26 - pending
09-18-2023 @ 21:50:26 - hook name: woocommerce_before_order_object_save
09-18-2023 @ 21:50:26 - pending
09-18-2023 @ 21:50:26 - hook name: wcs_new_order_created
09-18-2023 @ 21:50:26 - pending
09-18-2023 @ 21:50:26 - hook name: woocommerce_before_order_object_save
09-18-2023 @ 21:50:26 - pending
09-18-2023 @ 21:50:26 - hook name: wcs_renewal_order_created
09-18-2023 @ 21:50:26 - pending
09-18-2023 @ 21:50:27 - hook name: woocommerce_before_order_object_save
09-18-2023 @ 21:50:27 - pending
09-18-2023 @ 21:50:29 - hook name: woocommerce_before_order_object_save
09-18-2023 @ 21:50:29 - pending
09-18-2023 @ 21:50:29 - hook name: woocommerce_pre_payment_complete
09-18-2023 @ 21:50:29 - pending
09-18-2023 @ 21:50:29 - hook name: woocommerce_payment_complete_order_status
09-18-2023 @ 21:50:29 - pending
09-18-2023 @ 21:50:29 - hook name: woocommerce_before_order_object_save
09-18-2023 @ 21:50:29 - completed
09-18-2023 @ 21:50:33 - hook name: woocommerce_payment_complete_order_status
09-18-2023 @ 21:50:33 - completed
09-18-2023 @ 21:50:33 - hook name: woocommerce_before_order_object_save
09-18-2023 @ 21:50:33 - completed
09-18-2023 @ 22:28:15 - hook name: woocommerce_before_order_object_save
09-18-2023 @ 22:28:15 - completed
6769515-zd-a8c
Here's a debug backtrace from one of these
10-02-2023 @ 22:28:08 - hook name: woocommerce_payment_complete_order_status
10-02-2023 @ 22:28:08 - priority 1
10-02-2023 @ 22:28:08 - pending
10-02-2023 @ 22:28:08 - hook name: woocommerce_payment_complete_order_status
10-02-2023 @ 22:28:08 - priority 99
10-02-2023 @ 22:28:08 - pending
10-02-2023 @ 22:28:11 - hook name: woocommerce_payment_complete_order_status
10-02-2023 @ 22:28:11 - priority 1
10-02-2023 @ 22:28:11 - pending
10-02-2023 @ 22:28:11 - hook name: woocommerce_payment_complete_order_status
10-02-2023 @ 22:28:11 - priority 99
10-02-2023 @ 22:28:11 - pending
10-02-2023 @ 22:28:15 - hook name: woocommerce_payment_complete_order_status
10-02-2023 @ 22:28:15 - priority 1
10-02-2023 @ 22:28:15 - completed
10-02-2023 @ 22:28:15 - Array
(
[0] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 310
[function] => hiro_payment_complete_order_status
)
[1] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 205
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[2] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/class-wc-subscriptions-renewal-order.php
[line] => 95
[function] => apply_filters
)
[3] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 312
[function] => maybe_record_subscription_payment
[class] => WC_Subscriptions_Renewal_Order
[type] => ::
)
[4] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 334
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[5] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 517
[function] => do_action
[class] => WP_Hook
[type] => ->
)
[6] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php
[line] => 405
[function] => do_action
)
[7] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php
[line] => 253
[function] => status_transition
[class] => WC_Order
[type] => ->
)
[8] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php
[line] => 151
[function] => save
[class] => WC_Order
[type] => ->
)
[9] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/abstracts/abstract-wc-stripe-payment-gateway.php
[line] => 568
[function] => payment_complete
[class] => WC_Order
[type] => ->
)
[10] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/compat/trait-wc-stripe-subscriptions.php
[line] => 368
[function] => process_response
[class] => WC_Stripe_Payment_Gateway
[type] => ->
)
[11] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/compat/trait-wc-stripe-subscriptions.php
[line] => 189
[function] => process_subscription_payment
[class] => WC_Stripe_Payment_Gateway
[type] => ->
)
[12] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 310
[function] => scheduled_subscription_payment
[class] => WC_Stripe_Payment_Gateway
[type] => ->
)
[13] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 334
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[14] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 517
[function] => do_action
[class] => WP_Hook
[type] => ->
)
[15] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-subscriptions/includes/gateways/class-wc-subscriptions-payment-gateways.php
[line] => 97
[function] => do_action
)
[16] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-subscriptions/includes/gateways/class-wc-subscriptions-payment-gateways.php
[line] => 81
[function] => trigger_gateway_renewal_payment_hook
[class] => WC_Subscriptions_Payment_Gateways
[type] => ::
)
[17] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 310
[function] => gateway_scheduled_subscription_payment
[class] => WC_Subscriptions_Payment_Gateways
[type] => ::
)
[18] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 334
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[19] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 565
[function] => do_action
[class] => WP_Hook
[type] => ->
)
[20] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/actions/ActionScheduler_Action.php
[line] => 56
[function] => do_action_ref_array
)
[21] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php
[line] => 88
[function] => execute
[class] => ActionScheduler_Action
[type] => ->
)
[22] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php
[line] => 169
[function] => process_action
[class] => ActionScheduler_Abstract_QueueRunner
[type] => ->
)
[23] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php
[line] => 139
[function] => do_batch
[class] => ActionScheduler_QueueRunner
[type] => ->
)
[24] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 310
[function] => run
[class] => ActionScheduler_QueueRunner
[type] => ->
)
[25] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 334
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[26] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 565
[function] => do_action
[class] => WP_Hook
[type] => ->
)
[27] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-cron.php
[line] => 191
[function] => do_action_ref_array
)
)
10-02-2023 @ 22:28:15 - hook name: woocommerce_payment_complete_order_status
10-02-2023 @ 22:28:15 - priority 99
10-02-2023 @ 22:28:15 - completed
10-02-2023 @ 22:28:15 - Array
(
[0] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 310
[function] => hiro_payment_complete_order_status_99
)
[1] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 205
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[2] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/class-wc-subscriptions-renewal-order.php
[line] => 95
[function] => apply_filters
)
[3] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 312
[function] => maybe_record_subscription_payment
[class] => WC_Subscriptions_Renewal_Order
[type] => ::
)
[4] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 334
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[5] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 517
[function] => do_action
[class] => WP_Hook
[type] => ->
)
[6] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php
[line] => 405
[function] => do_action
)
[7] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php
[line] => 253
[function] => status_transition
[class] => WC_Order
[type] => ->
)
[8] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php
[line] => 151
[function] => save
[class] => WC_Order
[type] => ->
)
[9] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/abstracts/abstract-wc-stripe-payment-gateway.php
[line] => 568
[function] => payment_complete
[class] => WC_Order
[type] => ->
)
[10] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/compat/trait-wc-stripe-subscriptions.php
[line] => 368
[function] => process_response
[class] => WC_Stripe_Payment_Gateway
[type] => ->
)
[11] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-gateway-stripe/includes/compat/trait-wc-stripe-subscriptions.php
[line] => 189
[function] => process_subscription_payment
[class] => WC_Stripe_Payment_Gateway
[type] => ->
)
[12] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 310
[function] => scheduled_subscription_payment
[class] => WC_Stripe_Payment_Gateway
[type] => ->
)
[13] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 334
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[14] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 517
[function] => do_action
[class] => WP_Hook
[type] => ->
)
[15] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-subscriptions/includes/gateways/class-wc-subscriptions-payment-gateways.php
[line] => 97
[function] => do_action
)
[16] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce-subscriptions/includes/gateways/class-wc-subscriptions-payment-gateways.php
[line] => 81
[function] => trigger_gateway_renewal_payment_hook
[class] => WC_Subscriptions_Payment_Gateways
[type] => ::
)
[17] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 310
[function] => gateway_scheduled_subscription_payment
[class] => WC_Subscriptions_Payment_Gateways
[type] => ::
)
[18] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 334
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[19] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 565
[function] => do_action
[class] => WP_Hook
[type] => ->
)
[20] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/actions/ActionScheduler_Action.php
[line] => 56
[function] => do_action_ref_array
)
[21] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php
[line] => 88
[function] => execute
[class] => ActionScheduler_Action
[type] => ->
)
[22] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php
[line] => 169
[function] => process_action
[class] => ActionScheduler_Abstract_QueueRunner
[type] => ->
)
[23] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php
[line] => 139
[function] => do_batch
[class] => ActionScheduler_QueueRunner
[type] => ->
)
[24] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 310
[function] => run
[class] => ActionScheduler_QueueRunner
[type] => ->
)
[25] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/class-wp-hook.php
[line] => 334
[function] => apply_filters
[class] => WP_Hook
[type] => ->
)
[26] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-includes/plugin.php
[line] => 565
[function] => do_action
[class] => WP_Hook
[type] => ->
)
[27] => Array
(
[file] => /home/1008028.cloudwaysapps.com/gjdwatdnsh/public_html/wp-cron.php
[line] => 191
[function] => do_action_ref_array
)
)
Thanks for the stack traces and information @WillBrubaker and @kaushikasomaiya.
This issue has been automatically closed by merging the proposed PR: #518. Given this fix is based on the theory outlined in this issue description, this may not end up fixing all instances of this bug. Keep an eye out and if it surfaces again, reopen the issue and we can try narrow it down further if we need to.
We had three cases recently where users reported renewal orders are switched directly to completed instead of going to Processing.
7079530-zen 7083560-zen 6820654-zen
In all cases, we've verified the product in question wasn't virtual and downloadable.
Upon investigating 7079530-zen, mysteriously
needs_processing
transients were found to be 0 for some renewal orders and all of them belonged to the same variable product.For other cases, it is yet to be verified if needs_processing transients are the root cause.
The closest theory I could build around this is the following:
https://github.com/Automattic/woocommerce-subscriptions-core/blob/88cc564fdbcd6f926ef04c894859556e0fb823af/includes/wcs-order-functions.php#L181
Subs core creates a renewal order using the above function. There are a couple of code lines before the line items are added actually.
In case some other code executes
needs_processing()
before the line items are added to the renewal order - this could result in transient value 0 and the order being pushed to completed directly.I am opening this report for investigation and tracking more such issues.