• Resolved Daniel

    (@ddumondgmailcom)


    Is there a way I can add the order’s total weight to the invoice?

    I was able to include the total weight on the admin/order page by putting the following code in functions.php

    add_action( 'woocommerce_checkout_update_order_meta', 'bbloomer_save_weight_order' );
     
    function bbloomer_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', 'bbloomer_delivery_weight_display_admin_order_meta', 10, 1 );
      
    function bbloomer_delivery_weight_display_admin_order_meta( $order ) {    
        echo '<p><strong>Order Weight:</strong> ' . get_post_meta( $order->get_id(), '_cart_weight', true ) . get_option( 'woocommerce_weight_unit' ) . '</p>';
    }

    Being able to add this to the invoice would be super helpful when creating shipping labels.

    • This topic was modified 1 year, 10 months ago by Daniel.
Viewing 4 replies - 1 through 4 (of 4 total)
  • moksha shah

    (@mokshasharmila13)

    Hi @ddumondgmailcom,

    Yes, maybe the fields you have added in WooCommerce can be added as new fields in our invoice. We need to check on your site how to get your new fields in our invoice.

    Regards,Moksha.

    Thread Starter Daniel

    (@ddumondgmailcom)

    Hi Moksha,

    I included the code I used above in functions.php

    That code will put the total cart weight of new orders underneath the billing info.

    Is there a hook I can use so that it would display underneath the email in the invoice instead?

    • This reply was modified 1 year, 10 months ago by Daniel.
    moksha shah

    (@mokshasharmila13)

    Hi @ddumondgmailcom

    For adding new fields in our invoice, please add the below code in your active theme’s functions.php file or use a plugin like Code Snippets:

    function example_custom_order_fields( $fields, $order ) {
        $new_fields = array();
          // print_r($order); 
        if( get_post_meta( $order->get_id(), '_cart_weight', true ) ) {
            $new_fields['_cart_weight'] = array( 
                'label' => 'Order Weight',
                'value' => get_post_meta( $order->get_id(), '_cart_weight', true )
            );
        }
        
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'example_custom_order_fields', 10, 2 );

    Please let us know if you need any other help.

    Regards,Moksha

    Thread Starter Daniel

    (@ddumondgmailcom)

    Moksha! You sir are a ROCK STAR! ?? Thank you so much!! ??

    • This reply was modified 1 year, 10 months ago by Daniel.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add Total Cart Weight to Invoice’ is closed to new replies.