For a weight based eCommerce store, when viewing WooCommerce order items, the admin may want to have the total weight of the individual items. In this tutorial, we are going to show how to add product weight in admin order item meta.

PHP Snippet: Show woocommerce product weight in admin order item meta
<?php
/**
* @snippet Show product weight in admin order item meta (UPDATED)
* @author Anjan Phukan
* @testedWith WooCommerce 7.4.1
* @tutorial https://www.zealopers.com/woocommerce-tutorials/woocommerce-show-product-weight-in-admin-order-item-meta/
*/
add_action( 'woocommerce_after_order_itemmeta', 'zlp_show_weight_admin_order_item_meta', 10, 3 );
function zlp_show_weight_admin_order_item_meta( $item_id, $item, $product ) {
// IF PRODUCT OR IT'S VARIATION HAS WEIGHT
if( $product->weight ){ ?>
<table cellspacing="0" class="display_meta">
<tbody>
<tr>
<th><?php _e( 'Total Weight:' ); ?></th>
<td><p><?php echo ($item->get_quantity())*($product->get_weight())." ".get_option('woocommerce_weight_unit'); ?></p></td>
</tr>
</tbody>
</table>
<?php }
}
To Customize the order meta box, we need to use the woocommerce hook called
woocommerce_after_order_itemmeta
. If you need more information on this hook then you can visit this link. Where to add this snippet?
You can place this PHP snippet at the end of your child theme’s functions.php
file. Please make sure you know what you are doing and take a backup of the file before making any changes.
Did it work for you?
Please let us know in the comments section below if the tutorial was helpful to you and the codes worked out for you as anticipated. The code was tested with Woocommerce version listed above.
Did it save your time and money? Please feel free to share it and/or Like us our Facebook Page.
Found this in a Google search and works great! Now, if you could total the weights up it would be fantastic.
Hi Mark, we are glad to know that it worked for you. Please feel free to contact us through our contact form and we will be happy to help you. Thank you.
Hi,
I tried this code and it works ok, but I get a Fatal Error message on my site and cannot figure out why 🙁
I am attaching a pic.
Fatal error: Uncaught Error: Call to a member function get_weight() on null in /home/seoticab/salvita.bg/wp-content/themes/flatsome-child/functions.php:102 Stack trace: #0 /home/seoticab/salvita.bg/wp-includes/class-wp-hook.php(307): zlp_show_weight_admin_order_item_meta(1339, Object(WC_Order_Item_Shipping), NULL) #1 /home/seoticab/salvita.bg/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(”, Array) #2 /home/seoticab/salvita.bg/wp-includes/plugin.php(474): WP_Hook->do_action(Array) #3 /home/seoticab/salvita.bg/wp-content/plugins/woocommerce/includes/admin/meta-boxes/views/html-order-shipping.php(55): do_action(‘woocommerce_aft…’, 1339, Object(WC_Order_Item_Shipping), NULL) #4 /home/seoticab/salvita.bg/wp-content/plugins/woocommerce/includes/admin/meta-boxes/views/html-order-items.php(81): include(‘/home/seoticab/…’) #5 /home/seoticab/salvita.bg/wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-items.php(41): include(‘/home/seoticab/…’) #6 /home/seoticab/salvita.bg/wp-admin/ in /home/seoticab/salvita.bg/wp-content/themes/flatsome-child/functions.php on line 102
Hi, Sorry but we couldn’t replicate the problem. Have you set weight for your products?
Hi @Tony, sorry for the late reply. But we have fixed the code now. Please try it and let us know if you find any issues in it. Thanks for your patience.
Hi there, thank you for this wonderful post. It is exactly what i needed. But i had to make one extra check:
– Check if $item is line_item
Hi Panos, good to know that. All the best. Thnaks.
You rule! That solved the error problem!
Hi @Diego, sorry for the late reply. But we have updated the code now. This should fix all the issues. Thanks for your patience.
This outputs a critical error in the meta area where the weight should display. Has anyone tested this lately?
Hi @Daniel, sorry for the late reply. But we have fixed the code now. Please try it and let us know if you find any issues in it. Thanks for your patience.