I used to use a plugin to add the total order weight to each order and display it on the orders page on the back end. However, HPOS broke this and I have been trying to write the code to implement it again. I have Frankensteined a few snippets I have found, as my PHP skills are very limited, and this is as far as I have gotten, I just can’t seem to get it to populate the values.
I know a lot of you will look at this and say to yourself, what an idiot, but hopefully, someone might be able to point me in the right direction
add_filter( 'manage_woocommerce_page_wc-orders_columns', 'add_order_weight_column' );
function add_order_weight_column( $columns ) {
$columns['total_weight'] = __( 'Weight', 'woocommerce' );
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'populate_order_weight_column_content', 10, 2 );
function populate_order_weight_column_content( $column ) {
if ( $column == 'total_weight' ) {
global $the_order;
$total_weight = $the_order->get_meta('_cart_weight');
if ( $total_weight > 0 ) {
echo wc_format_weight( $total_weight );
} else {
_e('N/A', 'woocommerce');
}
}
}
The column doesn’t need to be sortable, I just need the total weight to be displayed