Woocommerce – Update previous custom columns code work with High-Performance Order Storage (HPOS)

I’ve been using the following code to display custom columns in the Woocommerce admin orders page:

// Add Order notes Column to Admin Orders Page
add_filter( 'manage_woocommerce_page_wc-orders_columns', 'woocommerce_add_order_notes_column' );

function woocommerce_add_order_notes_column( $columns ) {
    return array_slice( $columns, 0, 8, true )
    + array( 'order_notes' => __( 'Order Notes', 'woocommerce' ) )
    + array_slice( $columns, 8, NULL, true );

    return $ordered_columns;
}

// Get Order notes
add_action( 'manage_woocommerce_page_wc-orders_custom_column' , 'woocommerce_show_order_notes_column', 10, 2 );

function woocommerce_show_order_notes_column( $column_name, $order_id ) {
    switch ( $column_name ) {
        case 'order_notes':
            $order = wc_get_order( $order_id );
            $note = $order->get_customer_note();
            if ( !empty($note) ) {
                echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $note ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
            } else {
                echo '<span class="na">–</span>';
            }
            break;
    }
}


// Add 'Pre-order Products' Column to Admin Orders Page
add_filter( 'manage_woocommerce_page_wc-orders_columns', 'woocommerce_add_preorder_products_tick_column' );

function woocommerce_add_preorder_products_tick_column( $columns ) {
    $ordered_columns = array();
    
    foreach( $columns as $key => $column ){
        $ordered_columns[$key] = $column;
        if( 'wc_actions' == $key ){
            $ordered_columns['preorder_products_tick'] = __( 'Pre-orders', 'woocommerce');
        }
    }

    return $ordered_columns;
}

// Get Pre-order Products
add_action( 'manage_woocommerce_page_wc-orders_custom_column' , 'add_items_to_preorder_products_tick_column' );

function add_items_to_preorder_products_tick_column( $colname ) {
    global $the_order;

    if( $colname == 'preorder_products_tick' ) {

        // get items from the order global object
        $order_items = $the_order->get_items();

        if ( !is_wp_error( $order_items ) ) {
            foreach( $order_items as $order_item ) {
            $product_id = $order_item->get_product_id();  
                if ( has_term( array( 'comic-book-pre-orders', 'dc-comics-pre-orders', 'image-comics-pre-orders', 'marvel-comics-pre-orders', 'other-publisher-pre-orders' ), 'product_cat', $product_id ) ) {
                    echo "✔";
                }
            }   
        }
    }
}


// Add 'Total Sales' column to the products list
// add column
add_filter( 'manage_edit-product_columns', 'column_total_sales_1', 20 );
// populate column
add_action( 'manage_posts_custom_column', 'column_total_sales_2' );
// make column sortable
add_filter('manage_edit-product_sortable_columns', 'column_total_sales_3');
// how to sort column
add_action( 'pre_get_posts', 'column_total_sales_4' );

function column_total_sales_1( $columns_array ) {
    return array_slice( $columns_array, 0, 8, true )
    + array( 'total_sales' => 'Total Sales' )
    + array_slice( $columns_array, 8, NULL, true );
}

function column_total_sales_2( $column_id ) {
    if( $column_id  == 'total_sales' )
        echo get_post_meta( get_the_ID(), 'total_sales', true );
}

function column_total_sales_3( $a ){
    return wp_parse_args( array( 'total_sales' => 'by_total_sales' ), $a );
}

function column_total_sales_4( $query ) {
    if( !is_admin() || empty( $_GET['orderby']) || empty( $_GET['order'] ) )
        return;
    if( $_GET['orderby'] == 'by_total_sales' ) {
        $query->set('meta_key', 'total_sales' );
        $query->set('orderby', 'meta_value_num');
        $query->set('order', $_GET['order'] );
    }
    return $query;
}

// Make stock column sortable
add_filter( 'manage_edit-product_sortable_columns', 'wcss_make_stock_sortable' );
function wcss_make_stock_sortable( $sortable_columns ) {

   $sortable_columns[ 'is_in_stock' ] = '_stock';
   return $sortable_columns;
}

I’m now in the process of updating to High-Performance Order Storage (HPOS) and this code no longer works.

Can anyone advise me how I can update the code to work with HPOS please, as I’m completely lost!

Any advise would be very much appreciated, thank you!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật