Get a Product Attribute in Cart

Would you like to display another product attribute or a custom one in cart? it's that simple!

Working lately with the cart, we had to display additional product info in cart. Some custom and default product attributes. To include product attributes in the quote item you will need to declare them in the catalog_attributes.xml file. Same logic like in Magento 1 but not in the config.xml file any more.

Just create a file under app/code/<Vendor>/<Module>/etc/catalog_attributes.xml and add the following code.

Afterwards you can easily copy the file

/vendor/magento/module-checkout/view/frontend/templates/cart/item/default.phtml 

under your theme directory 

/app/design/frontend/<Vendor>/<theme>/Magento_Checkout/templates/cart/item/default.phtml 

and then you can add the line to display the attribute <?php echo $product->getCustomAttribute(); ?>

Will be back soon with another post about how we can do the same in the mini cart.

Feel free to share this post and ask your questions in the comments below.

Till next time!