The root cause of this issue is because when we call functions like woocommerce_wp_select(), WC will attempt to fetch the value to display in the element for us by getting it from the global post. However of HPOS admin screens, the global post object doesn't exist.
WC in 6.9.0 added a way to specify the object to circumvent the requirement on the global post. This PR uses a combination of approaches to fix this issue:
Where possible just specify the value via the $field['value'].
Adding a wrapper for woocommerce_wp_select()
How to test this PR
Enable HPOS tables.
Purchase a subscription.
Go to the WooCommerce > Subscriptions screen.
Edit a subscription.
On trunk you will get the Trying to get property 'ID' of non-object errors mentioned above.
On this branch there shouldn't be any errors.
Product impact
[x] Added changelog entry (or does not apply)
[ ] Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
[ ] Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
[ ] Added deprecated functions, hooks or classes to the spreadsheet
Fixes #299
Description
On HPOS environments when viewing the edit subscription screen, you'd get a bunch of the following error:
There's an open issue on WC for this https://github.com/woocommerce/woocommerce/issues/35543.
The root cause of this issue is because when we call functions like
woocommerce_wp_select()
, WC will attempt to fetch the value to display in the element for us by getting it from the global post. However of HPOS admin screens, the global post object doesn't exist.WC in 6.9.0 added a way to specify the object to circumvent the requirement on the global post. This PR uses a combination of approaches to fix this issue:
$field['value']
.woocommerce_wp_select()
How to test this PR
Trying to get property 'ID' of non-object
errors mentioned above.Product impact