-1

I am trying to display the data and time for the last time the product was updated.

<?php

$product = $block->getProduct();

?>

<h1><?php echo $product->getData('spec_sheet'); 
?></h1>

<span><?php echo $product->getUpdated_At();?></span>

I am not getting any errors, but it also isn't displaying anything.

Edit: Moved it to a different template

<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/**
 * Product additional attributes template
 *
 * @var $block \Magento\Catalog\Block\Product\View\Attributes
 */
?>
<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
?>
<?php if ($_additional = $block->getAdditionalData()): ?>
<div class="additional-attributes-wrapper table-wrapper">
    <table class="data table additional-attributes" id="product- 
attribute-specs-table">
        <caption class="table-caption"><?= /* @escapeNotVerified */ __('More Information') ?></caption>
        <tbody>
        <?php foreach ($_additional as $_data): ?>
            <tr>
                <th class="col label" scope="row"><?= $block- 
 >escapeHtml(__($_data['label'])) ?></th>
                <td class="col data" data-th="<?= $block- 
 >escapeHtml(__($_data['label'])) ?>"><?= /* @escapeNotVerified */ 
$_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?php endif;?>
<div class="spectab"><?php echo $_product- 
>getData('specification_tab'); ?></div>
<div><?php echo $product->getUpdated_At(); ?></div>

Now I get- Notice: Undefined variable: product

I changed the last line to

<div><?php echo $_product->getUpdated_At(); ?></div>

And the error clears but nothing displays.

2 Answers 2

2

Try <?php echo $product->getUpdatedAt(); ?>

1
  • Same issue. That is the way I tried it first. Just to make sure I tried it that way again and still getting nothing. I did flush cache after each change. Apr 22, 2019 at 21:06
0

At the end of the last template I used this instead-

<div><?php echo $_product->getData('updated_at'); ?></div>  

And it works!

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.