Automattic / woocommerce-subscriptions-core

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

Reorder the subscription line items metabox on hpos environments #369

Closed james-allan closed 1 year ago

james-allan commented 1 year ago

Fixes #338

Description

On HPOS environments the edit subscription screen metaboxes were appearing in the incorrect order - the line items meta box appeared above the subscription data. The reason this happens is because of slight differences in how the metaboxes get registered on HPOS and CPT environments.

On CPT the add_meta_boxes hook is triggered by WordPress core and we can register our metaboxes before WC do for our subscription data to appear first.

On HPOS the add_meta_boxes hook is triggered by WooCommerce core after they have registered their metaboxes. This results in our metaboxes appearing after theirs.

image

Unforunetly WP remembers the order that metaboxes are registered and so this PR fixes that by forcibly removing the order items metabox from the global and re-registers it after we've registered the subscriptions-related ones.

How to test this PR

  1. Enable HPOS.
  2. Purchase a subscription.
  3. Go to the WooCommerce > Subscriptions list table.
  4. Click on a subscription to edit it.
    • On trunk you notice that the line items metabox appears at the top of the screen (see screenshot above).
    • On this branch the metabox order is correct. Subscription-data -> line items -> downloads -> custom meta - related orders etc.

Note This change shouldn't impact CPT stores at all.

Product impact