Closed james-allan closed 2 months ago
I was also generally curious about why the change from using get_checkout_fields() because I thought generating the getter function and checking is_callable against the order would be enough to filter out these errors.
Yeah so the reason for changing it to use get_address_fields()
is because the old function returned the filtered list of fields that are displayed on the checkout. Anyone using a plugin that adds custom fields to the checkout would have their fields returned.
So, in the end using get_checkout_fields()
wouldn't fix the issue. If anyone hooked onto woocommerce_checkout_fields
and retuned a field with a key that also maps to an order getter (eg user
) it would still call $order->get_user()
.
In this PR I've limited it to only actually return address values. To do that I had to change the source of address fields and that's the WC()->countries->get_address_fields()
function.
Fixes https://github.com/woocommerce/woocommerce-subscriptions/issues/4627
Description
When a customer pays for a failed/pending renewal order, we pre-populate the checkout fields with address values from the order.
The function responsible for doing that is WCS_Cart_Renewal::checkout_get_value().
This function, prior to this PR, used
wcs_get_objects_property()
to pull these values for the checkout. That function is wide open in terms of what it could fetch and return. ie it attempts to call getters and then meta data and so any order property or meta is returnable in this case.This level of openness can lead to issues when stores use custom checkout fields. Eg in the issue description, the customer has a
user
field which leadswcs_get_objects_property()
to pull theWP_User
object from the order and attempts to put that into the checkout field.This PR fixes this by limiting this function to only fetch address values. From the function description itself, I don't believe this broad nature was intended.
How to test this PR
trunk
notice the PHP error notice indicating that anWP_User
object cannot be converted etc.Testing intended functionality.
Product impact