Closed magnuskl closed 7 months ago
Hey Magnus,
Thank you for the incredibly detailed bug report!
I love the amount of effort you put into it 🤩
I've now pushed a fix which'll make it's way into the plugin repository shortly 😄
No problem. I am glad that this issue could be resolved.
Description
A fatal error occurs when
get_agreement_id_from_order()
is called. The issue seems to stem from the function not specifying['order_type' => 'any']
as an argument or performing appropriate checks when callingwcs_get_subscriptions_for_order()
, leading to a situation where$subscriptions
typically becomesnull
, andget_meta()
is subsequently called on a non-existent subscription object.Steps to Reproduce
test.php
:wp-cli
:wcs_get_subscriptions_for_order()
is called without the$args
argument, it should return an empty array. When called with['order_type' => 'any']
as the$args
argument, it should return an array of the associated subscription objects.Expected Behavior
get_agreement_id_from_order()
should handle orders of any type, including renewals, by specifying the order type as any when callingwcs_get_subscriptions_for_order()
.Actual Behavior
A fatal error occurs due to a null reference when attempting to call
get_meta()
on a non-existent subscription object.Proposed Solution
Modify
get_agreement_id_from_order()
to specify the order type as any when callingwcs_get_subscriptions_for_order()
:Environment
Additional Context