Reputation: 21
I would like to add a Text depends on selected Attribute option: I create a Attribute with the optiones YES or NO. I want to create with php if I select in the Admin Panel yes that if should start another php code (that will show a few text on the category pages) But if I select No it should not run through the code, I mean don't display the text
Upvotes: 0
Views: 726
Reputation: 1704
If you created a Yes/No attribute (select Yes/No for the Catalog Input Type field), then you can check the value simply using
$_product->getData('my_attribute_code');
This will return either 0
or 1
.
So if you try
if($_product->getData('my_attribute_code')){
echo 'My text';
}
Note that depending on the context you may have to load the product first to get this value, so if nothing comes out of the getAttribute function, so you may have to execute this code before the previous one :
$_product->load($_product->getId())
And this should work.
EDIT: Note that this will not work if you create a dropdown attribute and set manually Yes and No as values. You need to chose Yes/No for the Catalog Input Type field of your attribute.
Cheers
Upvotes: 1