0

I want to add an icon/image to the attribute Country of Manufacture. I found something that sort of works but not fully.

https://www.reddit.com/r/Magento/comments/3ntvds/outputting_a_flag_icon_for_country_of_manufacture/

My plan was to use Country of Manufacture as a way to add an image that says "Made In Usa". This would only show when someone selects United States.

The code attaches it to all products and not just the ones that are made in usa.

This code works but I don't know how to add the image - it just shows the name of the country. I thought about doing CSS with background image but I would need a class.

<?php echo $_product->getAttributeText('country_of_manufacture');?>
1

You could use the option id for CSS classes

<span class="country-<?php echo $_product->getData('country_of_manufacture') ?>"></span>

Or check if an image with the name of the attribute exists and if so, display it as <img>, as in this similar question: DIsplay attribute image if it exists in folder

4
  • The span with class didn't work :( – user32527 Mar 22 '16 at 20:25
  • how so? it should result in something like class="country-123" and then you need to write your CSS accordingly – Fabian Schmengler Mar 22 '16 at 20:26
  • where does the 123 come into play? – user32527 Mar 22 '16 at 20:29
  • This is the internal value of the attribute instead of the store label that you get with getAttributeText(). Try it out to see which countries have which values. – Fabian Schmengler Mar 22 '16 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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