Skip to content

Commit

Permalink
Adding the DK invoice column to the legacy order table (#172)
Browse files Browse the repository at this point in the history
When using the posts table to store orders, different actions and filters are used than in the new "High-performance order storage", which is currently the default way to store orders.

This uses those "legacy" hooks display the DK invoice number.
  • Loading branch information
aldavigdis authored Jul 18, 2024
1 parent a90146c commit f59339c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
44 changes: 23 additions & 21 deletions src/Hooks/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -66,13 +52,26 @@ 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' ),
10,
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',
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions style/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f59339c

Please sign in to comment.