• My below function works and adds an entry to the backend order screen. If anyone has a better, best-practice method, please feel free to comment.

    function order_custom_field_function_name($order)
    {
        $order_id     = $order->id;
        $items        = $order->get_items();
        $total_weight = 0;
        foreach ($items as $item) {
            $item_metas  = get_post_meta($item['product_id']);
            $weight      = $item_metas['_weight']['0'];
            $quantity    = $item['qty'];
            $item_weight = ($weight * $quantity);
            $total_weight += $item_weight;
        }
        $total_weight = $total_weight / 1000;
        echo "<p><strong>Total Weight: <span style='color:green;'>" . $total_weight . "</span></strong> kg</p>";
    }
    
    add_action('woocommerce_admin_order_data_after_billing_address', 'order_custom_field_function_name', 10, 1);
  • The topic ‘My solution for backend total weight function in order view’ is closed to new replies.