Trying to display the 'country_of_manufacture' attribute on product view with extra html if value exists. Why does this code not work?

magento.stackexchange https://magento.stackexchange.com//questions/37611

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; ?>
Was it helpful?

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
scroll top