1

How can I fetch custom product attribute value such as size when it's added to the cart?

I want to show the size selected in an add to cart popup (which contains all product details)!

Any help will be appreciated.

1
  • do you mean, you want the value of selected option from page, right? Jun 23, 2018 at 13:02

2 Answers 2

2

Use below, it worked for me:

$_helper = $this->helper('Magento\Catalog\Helper\Output');
echo $_attributeValue = $block->getProduct()->getResource()->getAttribute('your_attribute')->getFrontend()->getValue($block->getProduct());
0

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);

$product->getCustomAttributeCode();`

1
  • Use of ObjectManager is not recommended in Magento 2. You can inject the class in constructor where required.
    – groy
    Mar 15, 2019 at 12:18

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.