• Resolved naimatanveer

    (@naimatanveer)


    Hello,

    Is there any way to display ‘total quantity of ordered items’ on the order details page and in email as well?

    Screenshot: https://paste.pics/BRCXN

    I tried different plugins and code but not working.

    Thank you

    Naima

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter naimatanveer

    (@naimatanveer)

    No response?

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    You could use something like this to display the total quantity in the admin Order screen like in your screenshot:

    
    function get_total_number_of_items_in_order( $order_id ) {
        $order = wc_get_order( $order_id );
        $total_quantity = 0;
        foreach ( $order->get_items() as $item_id => $item ) {
           $quantity = $item->get_quantity();
           $total_quantity += $quantity;
        }
        return $total_quantity;
    }
    
    function display_total_quantity_in_order_details( $order_id ) {
        $total_quantity = get_total_number_of_items_in_order( $order_id );
        ?>
    
                <tr>
                    <td class="label"><?php esc_html_e( 'Total Quantity:', 'woocommerce' ); ?></td>
                    <td width="1%"></td>
                    <td class="total">
                        <?php echo $total_quantity; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
                    </td>
                </tr>
    
        <?php
    }
    
    add_action( 'woocommerce_admin_order_totals_after_discount', 'display_total_quantity_in_order_details', 10 );

    `

    As for the emails, you could override the email template file for any emails you want to add it to, then use the method above to get the total number of items and display it where you want in the email. We have a guide for overriding template files here:
    https://docs.woocommerce.com/document/template-structure/

    MayKato

    (@maykato)

    Hi @naimatanveer

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. If you have further questions, please feel free to open a new topic.

    Hey,

    I want to use this code as well. This works!
    Is it possible to add a rule that only counts the total of products who have tag X?

    Thanks!!!

    Kind regards,

    Jeroen

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display total number of ordered items on order details page and email’ is closed to new replies.