Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions includes/admin/class-wc-amazon-payments-advanced-order-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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(
Expand Down
18 changes: 18 additions & 0 deletions includes/class-wc-amazon-payments-advanced-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading