I have two custom product attributes that I'm using in my product page template files. One of them doesn't seem to work and I'm wondering if it's something to do with the attribute code.

The attribute codes are:

  • small_promo
  • c2c_height_1

This works:

<?php if ($block->getProduct()->getSmallPromo()): ?>
    <!-- do something -->
<?php endif; ?>

This doesn't work:

<?php if ($block->getProduct()->getC2cHeight1()): ?>
    <!-- do something -->
<?php endif; ?>

Is this bit wrong: getC2cHeight1 ? Is there another method I could try?


Need to check c2c_height_1 attribute settings correct set or not

enter image description here

another method to get attribute value.

template code

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

    $heightattribute = $_product->getResource()->getAttribute('c2c_height_1');                  
    if ($heightattribute) 
        $C2cHeightValue = $heightattribute ->getFrontend()->getValue($_product);
        echo $C2cHeightValue;

I hope this will help you

  • Your method worked, thank you. – Jarxberg Apr 30 '20 at 17:16
  • Welcome @Jarxberg – Devidas Apr 30 '20 at 17:17

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.