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? Commented Jun 23, 2018 at 13:02

3 Answers 3

3

Use below, it worked for me:

$_helper = $this->helper('Magento\Catalog\Helper\Output');
$product = $block->getProduct();

echo $_attributeValue = $product->getResource()->getAttribute('your_attribute')->getFrontend()->getValue($product);
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
    Commented Mar 15, 2019 at 12:18
0

Try this:

$product->getData("attribute_code");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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