I'm trying to display something in the product page if a YES/NO attribute is set to YES. Actually the only way I found to do this in multilingual magento 2.1.8 is :

if($_product->getAttributeText('MY_ATTRIBUTE') == 'Oui' || $_product->getAttributeText('MY_ATTRIBUTE') == 'Yes') {
    echo "Set to Yes";
} else {
    echo "Set to No";

This method needs to test the YES/NO answer for every language but I'm pretty sure there's a better way to do this...

Thanks for your help


1 Answer 1


You should use boolean value instead of string to check Yes/No value, use



$yesNo = $_product->getData('attribute_code');

if($yesNo) {
    //value is set to Yes
} else {
    //value is set to No


For example, if your attribute code is myattribute then you can also use get() method to get attribute method


  • done but not enough reputation for now, new on this forum... but still thanks a lot
    – cap340
    Sep 4, 2017 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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