For tracking purposes, or maybe because your shop manager needs to be aware of this, saving the total weight of each order and displaying it on the single order admin page is quite simple.
That’s right – WooCommerce does not save this value by default. You either need to save it yourself into the “order meta” or recalculate the weight based on the order items and their quantities. Here, we’ll cover option one (saving is better than calculating in regard to performance).
Enjoy ๐
Display the order weight @ order admin
PHP Snippet: Save Order Weight & Display It @ WooCommerce Order Admin
WooCommerce: Create a Custom Order Status All WooCommerce orders go to either “processing”, “completed”, “on-hold” and other default order statuses based on the payment method and...
Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.
If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!
Need Help with WooCommerce?
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Rodolfo Melogli
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.
Hey Daniel, thanks so much for your comment! I just retested this on the latest version of WooCommerce and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Would this might be the issue?
I added the snippet to code snippets, and then I had it set to “Only run in administration area”.
Maybe the “woocommerce_checkout_update_order_meta” runs on front-end?
Hi Claudio, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello, I tested your code and it works fine. but it is possible to display the total sales by weight in the form of a report, in tonnes for example. ex: product1 = 1000 tonnes or by product category. ex: cat1 = 500 tonnes
Hi Zambol thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello and many thanks for this snippet !
I added this code and it works really good , but only in the orders coming from the front end.
When i manually add an order from the admin area , the order weight is not being updated ๐
Any ideas why?
Many thanks
Hi Rodolfo,
I use this code and work really well.
But Now I m using the follow code to resolve a big delay of Webhooks in WooCommerce. when I use this code the Webhooks work really fast but Your code is ignored
Thanks for this handy snippet of code. I will give it a shot to check if it works with new orders. MEanwhile i have a question and that is can we include the order weight in the new order emails which is sent to the admin. Please comment.
Hello Abhinav, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Perusi, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Added them for you ๐ Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Thanks for this…
I already have 2 of them in my functions.php ๐ One to show on the “orders overview” page and one inside the order and print it on the order email – that is on my table when I am doing / packing and printing the Shipment label
Any chance it can be combined into one – to rule them all?
Here is the two snippets
/**
* Here is that custom function that will show on "Order page overview" the total weight pr. order
* gist.github.com/kloon/5299119
*/
add_filter( 'manage_edit-shop_order_columns', 'woo_order_weight_column' );
function woo_order_weight_column( $columns ) {
$columns['total_weight'] = __( 'Weight', 'woocommerce' );
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'woo_custom_order_weight_column', 2 );
function woo_custom_order_weight_column( $column ) {
global $post, $woocommerce, $the_order;
if ( empty( $the_order ) || $the_order->id != $post->ID )
$the_order = new WC_Order( $post->ID );
if ( $column == 'total_weight' ) {
$weight = 0;
if ( sizeof( $the_order->get_items() ) > 0 ) {
foreach( $the_order->get_items() as $item ) {
if ( $item['product_id'] > 0 ) {
$_product = $the_order->get_product_from_item( $item );
if ( ! $_product->is_virtual() ) {
$weight += $_product->get_weight() * $item['qty'];
}
}
}
}
if ( $weight > 0 )
print $weight . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) );
else print 'N/A';
}
}
Questions? Feedback? Support? Leave your Comment Now! _____
If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)
With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.
Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.
This code no longer works. It displays “Order Weight: lbs”, but no number. ๐
Hey Daniel, thanks so much for your comment! I just retested this on the latest version of WooCommerce and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
D’oh!
Would this might be the issue?
I added the snippet to code snippets, and then I had it set to “Only run in administration area”.
Maybe the “woocommerce_checkout_update_order_meta” runs on front-end?
Could be, yes, give it a go!
Hi! Is there a way to show this information on the Order tab of the Account Frontend?
Thanks!
Hi Claudio, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello, I tested your code and it works fine. but it is possible to display the total sales by weight in the form of a report, in tonnes for example. ex: product1 = 1000 tonnes or by product category. ex: cat1 = 500 tonnes
Hi Zambol thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello and many thanks for this snippet !
I added this code and it works really good , but only in the orders coming from the front end.
When i manually add an order from the admin area , the order weight is not being updated ๐
Any ideas why?
Many thanks
No idea sorry, you probably need to slightly edit the code
Hi Rodolfo,
I use this code and work really well.
But Now I m using the follow code to resolve a big delay of Webhooks in WooCommerce. when I use this code the Webhooks work really fast but Your code is ignored
add_filter( ‘woocommerce_webhook_deliver_async’, ‘__return_false’ );
Not sure Edoardo!
hi Rodolfo,
Thanks for this handy snippet of code. I will give it a shot to check if it works with new orders. MEanwhile i have a question and that is can we include the order weight in the new order emails which is sent to the admin. Please comment.
Hello Abhinav, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello
I tried but the problem is that code does not show value (Order Weight: kg). How can I fix that? Maybe there is a problem with code on WordPress 5.3.2
This will only work for NEW orders and also if ALL products in the order have weight – let me know
Hello,
Is there a way to show variation weight or variation description on individual order-item-line? So, not the total weight, just individual!!
Hope you`ll help
Hi Perusi, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Ohhh I forgot the php tags ๐ And I can’t edit — Sorry!
Added them for you ๐ Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Rodolfo,
Thanks for this…
I already have 2 of them in my functions.php ๐ One to show on the “orders overview” page and one inside the order and print it on the order email – that is on my table when I am doing / packing and printing the Shipment label
Any chance it can be combined into one – to rule them all?
Here is the two snippets
And the second Snippet (If I add yours to the buttom of this … The site crashes? ๐
Do you think this would be better transferred to the order details and to the print order or packing list.
If for example, the shipping does not have access to the woocommerce backend.
Hey Roberta, yes, you can display it wherever you like – just change hook ๐