Home » WooCommerce: Save & Display Order Total Weight

WooCommerce: Save & Display Order Total Weight

by Tutor Aspire

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 @ Order Admin

/**
 * @snippet       Save & Display Order Total Weight - WooCommerce Order
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 3.6.4
 * @donate $9     https://tutoraspire.com
 */

add_action( 'woocommerce_checkout_update_order_meta', 'tutoraspire_save_weight_order' );

function tutoraspire_save_weight_order( $order_id ) {
    $weight = WC()->cart->get_cart_contents_weight();
    update_post_meta( $order_id, '_cart_weight', $weight );
}

add_action( 'woocommerce_admin_order_data_after_billing_address', 'tutoraspire_delivery_weight_display_admin_order_meta', 10, 1 );
 
function tutoraspire_delivery_weight_display_admin_order_meta( $order ) {    
    echo '

Order Weight: ' . get_post_meta( $order->get_id(), '_cart_weight', true ) . get_option( 'woocommerce_weight_unit' ) . '

'; }

You may also like