Having trouble with a custom field. It's a plain text field, called special_note.
<?php $specnote = $_product->getResource()->getAttribute('special_note');
if ($specnote) {
echo "<div id='specialnote'>".$specnote->getFrontend()->getValue($_product)."</div>";
}
?>
The specialnote div is always showing up, even when there's data. I've tried variations like if (!empty($specnote))
and if (!isnull($specnote))
to no avail.
How do I make is so that the div only shows up when it's been populated?
Additional info: this is in the file /app/design/frontend/mytheme/theme/template/catalog/product/view.phtml
Field is set up in magento as a 'text field' – and the settings "Visible on Product View Page on Front-end" and "Used in Product Listing" are both set to yes.
Best Answer
Does not return the result you are expecting.
That code, returns an instance of the product attribute
special_note
If the attribute exists or an empty instance of a product attribute if the attribute does not exist. So if you use the result in anif
statement it will always evaluate totrue
.Try using this code: