diff --git a/includes/admin/class-wc-amazon-payments-advanced-order-admin.php b/includes/admin/class-wc-amazon-payments-advanced-order-admin.php index 49411c52..d7c02942 100644 --- a/includes/admin/class-wc-amazon-payments-advanced-order-admin.php +++ b/includes/admin/class-wc-amazon-payments-advanced-order-admin.php @@ -42,9 +42,13 @@ public function order_actions() { * Non AJAX handler that performs order actions. */ public function order_actions_non_ajax() { - $screen_to_check = WC_Amazon_Payments_Advanced_Utils::get_edit_order_screen_id(); + $allowed_screens = array( + WC_Amazon_Payments_Advanced_Utils::get_edit_order_screen_id(), + WC_Amazon_Payments_Advanced_Utils::get_edit_subscription_screen_id(), + ); - if ( get_current_screen()->id !== $screen_to_check ) { + $current_screen = get_current_screen(); + if ( ! $current_screen || ! in_array( $current_screen->id, $allowed_screens, true ) ) { return; } @@ -136,9 +140,12 @@ public function meta_box( $screen, $order ) { return; } - $screen = WC_Amazon_Payments_Advanced_Utils::get_edit_order_screen_id(); + $default_screens = array( + WC_Amazon_Payments_Advanced_Utils::get_edit_order_screen_id(), + WC_Amazon_Payments_Advanced_Utils::get_edit_subscription_screen_id(), + ); - $post_types = apply_filters( 'woocommerce_amazon_pa_admin_meta_box_post_types', array( $screen ) ); + $post_types = apply_filters( 'woocommerce_amazon_pa_admin_meta_box_post_types', $default_screens ); foreach ( $post_types as $post_type ) { add_meta_box( diff --git a/includes/class-wc-amazon-payments-advanced-utils.php b/includes/class-wc-amazon-payments-advanced-utils.php index 287e65e2..519eca3d 100644 --- a/includes/class-wc-amazon-payments-advanced-utils.php +++ b/includes/class-wc-amazon-payments-advanced-utils.php @@ -27,6 +27,24 @@ public static function get_edit_order_screen_id() { : 'shop_order'; } + /** + * Returns the edit subscription's screen id. + * + * Takes into consideration if HPOS is enabled or not. + * + * @return string + */ + public static function get_edit_subscription_screen_id() { + // Fall back to classic post type screen id. + if ( ! function_exists( 'wc_get_container' ) || ! class_exists( 'Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) ) { + return 'shop_subscription'; + } + + // HPOS screen id uses wc-orders page with order type suffix. + return wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() + ? wc_get_page_screen_id( 'shop-subscription' ) + : 'shop_subscription'; + } /** * Get non required fields.