Closed dmvrtx closed 1 year ago
6064183-zen
While I disagree that the line from the year 2018 shouldn't start causing issues now and there are more calls of woocommerce_update_order scattered across various plugins without passing second argument, I believe this specific case is worth being fixed.
I am the developer who wrote the explanation you quoted and would be glad to clarify this aspect since you seem to partially disagree with my rationale.
The WooCommerce change is from 2019 but that doesn't mean that every plugin handling WooCommerce orders started adopting that change right away. This problem started happening now with our plugin just because we decided to take advantage of the second parameter passed to the callback function by the woocommerce_update_order
hook. By the way, thanks to that use, we avoid a rather expensive call to wc_get_order()
with the $order_id
, which is the exact reason why WooCommerce added that second parameter, to begin with.
Now, when you call do_action
on a hook that is originally defined in another plugin, it is your responsibility to comply with how that hook is originally defined. Otherwise, all the plugins that follow the original definition and want to take advantage of all its parameters – which is perfectly admissible by the original definition – will inevitably trigger a fatal error when used in combination with your plugin as well as all the various plugins that call do_action
on that hook with any missing parameter. It is just a matter of time before more and more plugins start using the second parameter to improve their performance – as we did with ours – and end up triggering the same error with your plugin.
Fortunately, in this case, the solution is just one variable away, on a single line of code.
I hope this better clarifies the situation and am glad I was able to bring this problem to your attention.
6062887-zen
Hi @dmvrtx - are we able to put a priority label on this? This would be helpful for our communications with customers around expectations. Thx!
38028383-hc - in this incident, the third party developer had this to say to the merchant who had an issue with their product (WooCommerce Wholesale Pro):
From April 17, 2019, the
do_action
calls for thewoocommerce_new_order
andwoocommerce_update_order
hooks (as well as many other similar hooks, such asnew_coupon
,new_customer
, etc) were changed to include the correspondent object as a second parameter (this is aimed at avoiding redundant and expensive calls to get an object from its ID). When the WooCommerce Subscriptions plugin runswoocommerce_update_order
on line 206 (of their code), the second parameter is omitted (which should be$subscription
in their case). Their use of that hook breaks any plugin that might use both parameters (as WooCommerce Wholesale Pro does).
I've gone ahead and put a 'High' priority issue on this for now since it appears to be a small fix that would support other developers who are using both parameters correctly in this common hook.
Describe the bug
Developers of the Wholesale Pro plugin had investigated the reason for the following error on the user's site (see details):
They believe the culprit is this line where
woocommerce_update_action
is called without passing a second argument, which shuld be$subscription
.Their reasoning is below:
While I disagree that the line from the year 2018 shouldn't start causing issues now and there are more calls of
woocommerce_update_order
scattered across various plugins without passing second argument, I believe this specific case is worth being fixed.Expected behavior
woocommerce_update_order
action is called with both order ID and order object.Actual behavior
woocommerce_update_order
action is called with order ID alone.Product impact
Additional context