I am working on a new site using Magento 2.2. This is my first project using Magento 2. Can anyone guide me how to add the product SKU to the order confirmation email?

When I go to Backend -> Marketing -> Email Templates -> edit the New Order Confirmation Template, I saw this {{layout handle="sales_email_order_items" order=$order area="frontend"}} which will output the order product details. But I am not sure which file I should edit to add the product SKU, thanks.


Override vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml to your theme


Now add sku <td class="item-sku"><?= $block->escapeHtml($block->getSku($_item)) ?></td> where you want to show sku

I added sku after product name here is final default.phtml

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

// @codingStandardsIgnoreFile

/** @var $block \Magento\Sales\Block\Order\Email\Items\DefaultItems */

/** @var $_item \Magento\Sales\Model\Order\Item */
$_item = $block->getItem();
$_order = $_item->getOrder();
    <td class="item-info<?php if ($block->getItemOptions()): ?> has-extra<?php endif; ?>">
        <p class="product-name"><?= $block->escapeHtml($_item->getName()) ?></p>
        <?php if ($block->getItemOptions()): ?>
            <dl class="item-options">
            <?php foreach ($block->getItemOptions() as $option): ?>
                <dt><strong><em><?= /* @escapeNotVerified */  $option['label'] ?></em></strong></dt>
                    <?= /* @escapeNotVerified */  nl2br($option['value']) ?>
            <?php endforeach; ?>
        <?php endif; ?>
        <?php $addInfoBlock = $block->getProductAdditionalInformationBlock(); ?>
        <?php if ($addInfoBlock) :?>
            <?= $addInfoBlock->setItem($_item)->toHtml() ?>
        <?php endif; ?>
        <?= $block->escapeHtml($_item->getDescription()) ?>
    <!-- Here add sku column --> 
    <td class="item-sku"><?= $block->escapeHtml($block->getSku($_item)) ?></td>
    <td class="item-qty"><?= /* @escapeNotVerified */  $_item->getQtyOrdered() * 1 ?></td>
    <td class="item-price">
        <?= /* @escapeNotVerified */  $block->getItemPrice($_item) ?>
<?php if ($_item->getGiftMessageId() && $_giftMessage = $this->helper('Magento\GiftMessage\Helper\Message')->getGiftMessage($_item->getGiftMessageId())): ?>
    <td colspan="3" class="item-extra">
        <table class="message-gift">
                    <h3><?= /* @escapeNotVerified */  __('Gift Message') ?></h3>
                    <strong><?= /* @escapeNotVerified */  __('From:') ?></strong> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
                    <br /><strong><?= /* @escapeNotVerified */  __('To:') ?></strong> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
                    <br /><strong><?= /* @escapeNotVerified */  __('Message:') ?></strong>
                    <br /><?= $block->escapeHtml($_giftMessage->getMessage()) ?>
<?php endif; ?>

Also you need to override vendor/magento/module-sales/view/frontend/templates/email/items.phtml for add new for sku


<th class="item-qty">
    <?= /* @escapeNotVerified */  __('Sku') ?>

OUTPUT: enter image description here

  • Do you happen to know how to add a product attribute by attribute code to the email as well?
    – Hongbin Yu
    Mar 15 '18 at 7:03
  • @PrincePatel So if I want to add my_sku attribute in email then can I use $_item->getMySku(); ? Mar 20 '18 at 5:51
  • @PrincePatel Okay. That $_tem->getId() will return item ID or product ID ? Mar 20 '18 at 6:06
  • $_item->getProduct()->getId(); will return the product ID. $_item->getMySku() will NOT return the value of the product attribute my_sku. I am actually working on add the product attribute to the email. No luck for now. I will keep you updated here once I find out.
    – Hongbin Yu
    Mar 20 '18 at 6:37
  • @KishanPatadia I have checked $_item object and it has [product_id] So you can get product id by $_item->getProductId() Mar 20 '18 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.