Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
85 stars 31 forks source link

[HPOS] Fix "ID on non-object" errors on the edit subscription screen #357

Closed james-allan closed 1 year ago

james-allan commented 1 year ago

Fixes #299

Description

On HPOS environments when viewing the edit subscription screen, you'd get a bunch of the following error:

Notice: Trying to get property 'ID' of non-object in
woocommerce/src/Internal/Utilities/COTMigrationUtil.php on line 99

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:

  1. Where possible just specify the value via the $field['value'].
  2. Adding a wrapper for woocommerce_wp_select()

How to test this PR

  1. Enable HPOS tables.
  2. Purchase a subscription.
  3. Go to the WooCommerce > Subscriptions screen.
  4. 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