Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
80 stars 29 forks source link

Double trigger of woocommerce_subscription_status_changed hook #629

Open kasus opened 1 month ago

kasus commented 1 month ago

Describe the bug

woocommerce_subscription_status_changed hook is double triggered when cancelling subscription. I did some backtrace and I can tell it's caused by this commit https://github.com/Automattic/woocommerce-subscriptions-core/commit/295cba2872732fd1ebcffb12db0841df44b8dd58#diff-bb9ad31c46d815893acb9985f14b98e7573480cfee40ac203639d61063b39f86

Specifically - woocommerce_subscription_status_changed hook triggers WCS_Email_Cancelled_Subscription, which calls for subscription save function, which triggers woocommerce_subscription_status_changed again, because it's in the middle of status_transition loop, and status_transition internal variable hasn't been cleared.