0

Please see attached screenshot: [![enter image description here][1]][1]

I created one custom product attributes ETA_DATE and I want to display same as attached image. How to display this attribute on product page?

enter image description here

4
  • Hello, did you found solution ?
    – Pawan
    Nov 30, 2018 at 16:31
  • No, I updated my question. Do you know how can I do?
    – kiran
    Nov 30, 2018 at 16:35
  • edit: {Magento2Root}/app/design/frontend/{Package}/{theme}/Magento_Catalog/templates/product/list.phtml and call <?php echo getEtaDate(); ?> Or <?php echo getAttributeText(eta_date); ?>
    – Pawan
    Nov 30, 2018 at 16:43

1 Answer 1

1

Try below code to get custom attribute value.

<?php echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($block->getProduct(), $block->getProduct()->getEtaDate(), 'Eta_Date')); ?>

Update:

app/design/frontend/CUSTOM/THEME/Magento_Catalog/templates/product/list.phtml

$attribute = $_product->getResource()->getAttribute('attribute_code');

// Get Value

$attributeValue = $attribute->getFrontend()->getValue($_product);

// Get Label

$attributeLabel = $attribute->getStoreLabel();

Note: Make sure “Visible on Product View Page on Front-end” and “Used in Product Listing” options under storefront Properties are set to Yes.

Update:

<?php 
if(!$_product->getIsSalable()):
    $attribute = $_product->getResource()->getAttribute('eta_date'); 
    $etaDate = $attribute->getFrontend()->getValue($_product); 
    $newDate = date("d/m/Y", strtotime($etaDate));
    $etaLabel = $attribute->getStoreLabel(); 
    echo $etaLabel." ".$etaDate;
endif;
?> 
8
  • In which file I'll use this code?
    – kiran
    Nov 29, 2018 at 21:49
  • if you want it after "Add to cart" button then app\design\frontend\Vendor\theme\Magento_Catalog\templates\product\view\addtocart.phtml use this file. Nov 29, 2018 at 21:51
  • this code is not working and I find addto cart file:vendor/magento/module-catalog/view/frontend/templates/product/addtocart.phtml I use this code but it doesn't show me custom attributes.
    – kiran
    Nov 29, 2018 at 21:58
  • What exactly your attribute code is? Its all Capital letters? Also, make sure that your file is coming from theme or from vendor? Nov 29, 2018 at 21:59
  • my attribute code is eta_date and I copy addtocart.phtml from vendor to app/design folder but this code is not working.
    – kiran
    Nov 30, 2018 at 15:34

Your Answer

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

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