0

I want to add the values of some custom attributes to the contents of the Details tab on the frontend Product page (where the Description is displayed). These values would be placed above the description.

I am not talking about adding a new tab. I want to simply add additional attribute values to an existing tab.

I have added a simple 'echo "TEST"' to THEME/Magento_Catalog/templates/product/view/description.phtml just to try and change the tab contents, but it had no effect. I am pretty new to Magento, so there may be an obvious answer, but I can't seem to figure it out. What am I missing?

  • Content > Widgets is actually very useful and will allow you to add a static block as well as other variable almost anywhere on any page. If you don't have too many of these attributes, creating static block content to show anywhere in the description tab is fairly easy. – dawhoo Jul 7 '17 at 21:29
1

vendor/magento/module-catalog/view/frontend/templates/product/view/attribute.phtml

You can override this file in your custom theme and add the custom attribute text before details tab content.

app/design/frontend/VendorName/ThemeName/Magento_Catalog/templates/product/view/attribute.phtml

I have added custom_attribute attribute in my local project and working fine. You can get custom attribute value like this : $_product->getCustomAttribute();

<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_call = $block->getAtCall();
$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();

$renderLabel = true;
// if defined as 'none' in layout, do not render
if ($_attributeLabel == 'none') {
    $renderLabel = false;
}

if ($_attributeLabel && $_attributeLabel == 'default') {
    $_attributeLabel = $_product->getResource()->getAttribute($_code)->getStoreLabel();
}
if ($_attributeType && $_attributeType == 'text') {
    $_attributeValue = ($_helper->productAttribute($_product, $_product->$_call(), $_code)) ? $_product->getAttributeText($_code) : '';
} else {
    $_attributeValue = $_helper->productAttribute($_product, $_product->$_call(), $_code);
}
?>
<?php if ($_attributeValue): ?>
    <?php /** This will display custom attribute value **/ ?>
    <?php if ($_code == 'description') : ?>
        <?php echo $_helper->productAttribute($_product, $_product->getCustomAttribute(), 'custom_attribute'); ?>
    <?php endif; ?>

    <?php if ($renderLabel): ?><strong class="type"><?= /* @escapeNotVerified */ $_attributeLabel ?></strong><?php endif; ?>
    <div class="value" <?= /* @escapeNotVerified */ $_attributeAddAttribute ?>><?= /* @escapeNotVerified */ $_attributeValue ?></div>
</div>
<?php endif; ?>

Please clear cache after changing the file. hope this is helpful.

0

use the given below attribute.phtml file.

THEME/Magento_Catalog/templates/product/view/attribute.phtml

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.