Try to replace the code snippet above for this one:
/**
* Add a column in the order list to show the invoice date
*
* See: https://www.ads-software.com/support/topic/invoice-date-column-in-order-list/#post-14245482
*/
add_filter( 'manage_edit-shop_order_columns', 'wpo_wcpdf_invoice_date_column', 9999 );
function wpo_wcpdf_invoice_date_column( $columns ) {
$insert_after = 'pdf_invoice_number';
$position = array_search( $insert_after, array_keys( $columns ) ) + 1;
// put the column after the Status/Invoice number column
return array_slice( $columns, 0, $position, true )
+ array( 'pdf_invoice_date' => __( 'Invoice Date', 'woocommerce-pdf-invoices-packing-slips' ) )
+ array_slice( $columns, $position, null, true ) ;
}
add_action( 'manage_shop_order_posts_custom_column', 'wpo_wcpdf_invoice_date_column_data', 10, 2 );
function wpo_wcpdf_invoice_date_column_data( $column, $post_id ) {
if ( $column == 'pdf_invoice_date' && $order = wc_get_order( $post_id ) ) {
add_filter( 'wpo_wcpdf_document_store_settings', '__return_false', 99992 );
$invoice = wcpdf_get_invoice( $order );
if ( $invoice && $invoice_date = $invoice->get_date() ) {
echo $invoice_date->date_i18n( wcpdf_date_format( $invoice, 'invoice_date' ) );
}
remove_filter( 'wpo_wcpdf_document_store_settings', '__return_false', 99992 );
}
}
add_filter( 'manage_edit-shop_order_sortable_columns', 'invoice_date_column_sortable');
function invoice_date_column_sortable( $columns ) {
$columns['pdf_invoice_date'] = 'pdf_invoice_date';
return $columns;
}
add_filter( 'request', 'request_query_sort_by_invoice_date' );
function request_query_sort_by_invoice_date( $query_vars ) {
global $typenow;
if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ), true ) ) {
if ( isset( $query_vars['orderby'] ) ) {
if ( 'pdf_invoice_date' === $query_vars['orderby'] ) {
$query_vars = array_merge( $query_vars, array(
'meta_key' => '_wcpdf_invoice_date',
'orderby' => apply_filters( 'wpo_wcpdf_invoice_date_column_orderby', 'meta_value' ),
) );
}
}
}
return $query_vars;
}
Hope it helps! ??