WooCommerce: Show Product Weight in Admin Order Item Meta

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.

Show product weight in admin order item meta
Show 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.

Feel free to contact us if you need help to implement this.

Share this post:
5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

11 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mark
Mark
2 years ago

Found this in a Google search and works great! Now, if you could total the weights up it would be fantastic.

Tony
1 year ago

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

Edit order “Order – май 20, 2022 @ 10_12 PM” ‹ Sal.jpg
Panos
Panos
1 year ago

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

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 ) {
   // product only
   if( $item->is_type( 'line_item' ) ) {
   // IF PRODUCT OR IT'S VARIATION HAS WEIGHT
   if($product->get_weight()){ ?>
      <table cellspacing="0" class="display_meta">
         <tbody>
            <tr>
               <th><?php _e( 'Total Weight:', 'flatsome-child' ); ?></th>
               <td><p><?php echo ($item->get_quantity())*($product->get_weight())." ".get_option('woocommerce_weight_unit'); ?></p></td>
            </tr>
         </tbody>
      </table>
   <?php } }
} 
Diego
Diego
Reply to  Panos
1 year ago

You rule! That solved the error problem!

Daniel
Daniel
1 year ago

This outputs a critical error in the meta area where the weight should display. Has anyone tested this lately?