Store and display WooCommerce order total weight

My friend (and awesome fellow at WooThemes) Gerhard wrote a few months ago a really nice snippet to add a new column in the WordPress administration edit order page to display the order weight. This snippet is really great but the order total weight will not be fully accurate if you change a product weight because the snippet calculates the order weight on the fly.

Let’s say a user buys product A, which weight is 10 on july 15th. User A purchases this product on the same day. But a week later you get a new version of product A that is slightly less heavy. You then edit product A weight and set it to 9. Gerhard’s snippet will display user’s A order total weight equal to 9. But if you send user A product former version of product A (the one that user A purchased) the right weight is 10, not 9. Does that makes sense?

So, in order to avoid this, i coded a quick snippet that saves the total order weight at the exact moment the order is made. The snippet then adds a new column in the orders list that displays the correct weight with the weight unit defined in WooCommerce settings. Simply place that code in functions.php in your theme folder:

Here is the result:

WooCommerce Order Total Weight
WooCommerce Order Total Weight

5 responses to “Store and display WooCommerce order total weight”

  1. luc

    I’m using the csv export plugin to create a csv file of all the orders. I would like to add the weight created by your code as an extra column. I can add an extra column with this:

    // add custom column headers
    function wc_csv_export_modify_column_headers( $column_headers ) {

    $new_headers = array(
    ‘column_1’ => ‘Column 1’,
    ‘column_2’ => ‘Column 2’,
    // add other column headers here in the format column_key => Column Name

    return array_merge( $column_headers, $new_headers );
    add_filter( ‘wc_customer_order_csv_export_order_headers’, ‘wc_csv_export_modify_column_headers’ );

    But so far, I haven’t been able to get any data to the column. Do you know a way? Thanks!

  2. andreaskarman

    I created the plugin Woo Orde Weight based on the concepts of this blog post.

    1. Well done, thanks for sharing!

  3. fryed

    Hi, thanks for the snippet. Is there a possibility to edit the order weight?

  4. shawhi2017

    Thanks – exactly what I wanted.
    How can I also add it into the order page?

Leave a Reply