Trying to display the 'country_of_manufacture' attribute on product view with extra html if value exists. Why does this code not work?
-
12-12-2019 - |
Question
This is the php code I wrote for our product view page. It should only show on the front end if the variable has a value. yet the html still shows even if the product does not have the variable defined. Note: This is specific to the magento predefined country of manufacture attribute.
<?php
$coManufacturer = $this->getProduct()->getAttributeText('country_of_manufacture');
?>
<?php if ($coManufacturer): ?>
<p><strong>Country of Origin:</strong> <?php echo $coManufacturer; ?></p>
<?php endif; ?>
Solution
Looks like the solution was to dump the var to understand what was being populated for the empty field of the attribute. Once I got that figured out, I was able to change the condition to this: ($coManufacturer!=" ")
which corrected the behavior. Thanks for your guys help!
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange