Is there a way to add product SKU on add to cart alert notification right now it shows the product name and I want to display the SKU also. Please see the attached screenshot. http://prntscr.com/l7cfjx

Thanks.

For your Magento version 2.2.2. We just need to override the add to cart controller: Magento\Checkout\Controller\Cart\Add

In execute method, we need to change the message (line 123 ~ 130)

     $message = __(
                    'You added %1 SKU: %2 to your shopping cart.',
                    $product->getName(),
                    $product->getSku()
                );

Later versions (for example 2.3), there are two places we need to change.

In execute method, we need to change

  $this->messageManager->addComplexSuccessMessage(
                        'addCartSuccessMessage',
                        [
                            'product_name' => $product->getName(),
                            'product_sku' => $product->getSku(),
                            'cart_url' => $this->getCartUrl(),
                        ]
                    );

We also need to change the template: view/frontend/templates/messages/addCartSuccessMessage.phtml

<?= $block->escapeHtml(__(
    'You added %1 , SKU: %2 to your <a href="%3">shopping cart</a>.',
    $block->getData('product_name'),
    $block->getData('product_sku')
    $block->getData('cart_url'),
), ['a']);

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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