cancel
Showing results for 
Search instead for 
Did you mean: 

Get custom attribute on the final_price.phtml file

Get custom attribute on the final_price.phtml file

Hello,

I would like to add a custom attribute (bum) in the final_price.phtml file.

I put this code: enter image description here

It doesn't work, nothing appears.

When I tried, <?php echo $_product->getBum(); I have this error message :

enter image description here

Fatal error: Call to a member function getBum() on null in /home/magento/www/app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/price/final_price.phtml on line 33

 

Can you help me please?

 

Thanks,

6 REPLIES 6

Re: Get custom attribute on the final_price.phtml file

try something like this: 

<?php
$_product = $block->getProduct();
$attvalue = $_product->getResource()->getAttribute('attribute_id')->getFrontend()->getValue($_product);
echo $attvalue;
?>

Re: Get custom attribute on the final_price.phtml file

Hello,

 

Thanks for your repply. When I try with your code, I have this error message :

 

Fatal error: Call to a member function getResource() on null in /home/magento/www/app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/price/final_price.phtml on line 14

Re: Get custom attribute on the final_price.phtml file

change the "attribute_id" for the atrribute id you want to call Smiley Happy  

Re: Get custom attribute on the final_price.phtml file

you can keep below code,

 

<?php
$_product = $block->getProduct();
$attvalue = $_product->getResource()->getAttribute('bum')->getFrontend()->getValue($_product);
echo $attvalue;exit;
?>

if issue solved, Click Kudos/Accept as solutions.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Get custom attribute on the final_price.phtml file

Buenas,

lamentablemente eso mismo probé yo también al principio pero

$_product = $block->getProduct();

es null.

 

Alguna otra sugerencia? Gracias!

Re: Get custom attribute on the final_price.phtml file

Finalmente lo logré haciendo:

$block->getSaleableItem()->getData();

o bien pasando el código del atributo como parámetro:

$block->getSaleableItem()->getData('attribute_code');

Espero que les sirva! Abrazo