diff --git a/src/Hooks/Admin.php b/src/Hooks/Admin.php index 5947b2d..9d5a6ed 100644 --- a/src/Hooks/Admin.php +++ b/src/Hooks/Admin.php @@ -35,24 +35,10 @@ public function __construct() { add_action( 'admin_menu', array( __CLASS__, 'add_menu_page' ) ); - if ( - ( - // Superlobal is not passed into anything. - // phpcs:ignore WordPress.Security.NonceVerification - isset( $_GET['page'] ) - ) - && - ( - // Superlobal is not passed into anything. - // phpcs:ignore WordPress.Security.NonceVerification - $_GET['page'] === '1984-dk-woo' || $_GET['page'] === 'wc-orders' - ) - ) { - add_action( - 'admin_init', - array( __CLASS__, 'enqueue_styles_and_scripts' ) - ); - } + add_action( + 'admin_init', + array( __CLASS__, 'enqueue_styles_and_scripts' ) + ); add_action( 'current_screen', @@ -66,6 +52,12 @@ public function __construct() { 10 ); + add_filter( + 'manage_edit-shop_order_columns', + array( __CLASS__, 'add_dk_invoice_column' ), + 10 + ); + add_action( 'woocommerce_shop_order_list_table_custom_column', array( __CLASS__, 'dk_invoice_column' ), @@ -73,6 +65,13 @@ public function __construct() { 2 ); + add_action( + 'manage_shop_order_posts_custom_column', + array( __CLASS__, 'dk_invoice_column' ), + 10, + 2 + ); + if ( Config::get_product_convertion_to_variation_enabled() ) { add_filter( 'bulk_actions-edit-product', @@ -109,13 +108,16 @@ public static function add_dk_invoice_column( array $columns ): array { /** * Action for the DK Invoice column in the orders table * - * @param string $column_name The column name (dk_invoice_id in our case). - * @param WC_Order $wc_order The WooCommerce order. + * @param string $column_name The column name (dk_invoice_id in our case). + * @param WC_Order|int $wc_order The WooCommerce order. */ public static function dk_invoice_column( string $column_name, - WC_Order $wc_order + WC_Order|int $wc_order ): void { + if ( is_int( $wc_order ) ) { + $wc_order = wc_get_order( $wc_order ); + } if ( $column_name === 'dk_invoice_id' ) { $invoice_number = $wc_order->get_meta( '1984_woo_dk_invoice_number', diff --git a/style/admin.css b/style/admin.css index 2456b95..ed07510 100644 --- a/style/admin.css +++ b/style/admin.css @@ -172,21 +172,21 @@ body.woocommerce_page_1984-dk-woo .wrap { display: none; } -.wc-orders-list-table .column-dk_invoice_id .dashicons { +table .column-dk_invoice_id .dashicons { padding: 4px 0px 4px 4px; } -.wc-orders-list-table .column-dk_invoice_id .debit_invoice { +table .column-dk_invoice_id .debit_invoice { color: rgb(0, 120, 60); font-weight: 600; } -.wc-orders-list-table .column-dk_invoice_id .credit_invoice { +table .column-dk_invoice_id .credit_invoice { color: #333; font-weight: 600; } -.wc-orders-list-table .column-dk_invoice_id .invoice_error { +table .column-dk_invoice_id .invoice_error { color: #900; font-weight: 600; }