Magento 2 Product Attributes – Get Attribute from Dropdown Yes/No

attributescustom-optionsmagento2productproduct-attribute

I have created a dropdown attribute with the options of "yes" and "no" with the hope to show an element with yes is selected in the admin. I have a few of these dropdown attributes that all show different icons depending if the product needs them. Unfortunately I can not get it to work. Here is my code.

<ul class="safety-footwear-icons">
<?php if($product->getAttributeText('safety_basic')=='yes'){ ?>
    <li class="sb">
        <span class="tooltiptext">SAFETY BASIC - EN ISO 20345:2011 + 200 joules toe protection</span>
    </li>
<?php } ?>

Best Answer

You need to do code like this :

<ul class="safety-footwear-icons">
<?php if($product->getSafetyBasic()){ ?>
    <li class="sb">
        <span class="tooltiptext">SAFETY BASIC - EN ISO 20345:2011 + 200 joules toe protection</span>
    </li>
<?php } ?>

NOTE: Just confirm product object is load before above code.