• Resolved defjam2oo1

    (@defjam2oo1)


    can someone tell me which snippet I can use to display the total number of products in the emails?
    I have a snippet that only shows me in the overview and I would like to see this in the e-mails as well

    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 );

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @defjam2oo1

    You can do this by modifying the e-mail template, with a bit of custom code to add the total number of products. Here’s a good place to get started:

    https://woocommerce.com/pt-br/posts/how-to-customize-emails-in-woocommerce/

    More specifically, you’d need to modify the “new order” e-mail template. To override and edit it copy /wp-content/plugins/woocommerce/templates/emails/admin-new-order.php to your theme folder: /wp-content/themes/mytheme/woocommerce/emails/admin-new-order.php.

    If you need help building this, I highly recommend contacting one of the services on our customizations page: https://woocommerce.com/customizations/

    I can also recommend the WooCommerce Developer Resources portal for resources on developing for WooCommerce.

    Finally, for advanced/development-oriented questions, you can visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Regards

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. Hopefully, the above info was helpful.

    If you have further questions, please feel free to open a new topic.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Total items in Admin new Order E-Mail’ is closed to new replies.