1

we created an attribute "Cash on delivery"

using Drop down we gave 2 values "Yes/No"

if the value is "Yes", we are displaying " Available".

if the value is "NO", its not displaying "Not Available". This is the Problem. If Attribute value = "NO", It should display "Not Available" in Frontend.

we are using following code.

<?php 
$attribute = $_product->getResource()->getAttribute('cod_available');
$attribute_value = $attribute ->getFrontend()->getValue($_product);
if ($attribute_value == "Yes")
{?>


<div class="two">?<p class="three"><?php echo "Available";?></p><?php 
 }

else
{?><i class="one"></i>


<p><?php   echo " Not Available";
}
?>
</p>
  • What is the problem on this? – Magento 2 Dec 3 '15 at 7:47
  • if attribute value = "NO", its not displaying " NOt available", I want to display " Not available" – user33510 Dec 3 '15 at 7:48
  • Share me your url? – Magento 2 Dec 3 '15 at 7:49
2

try this because for yes and no values are saved 0 and 1

 <?php 
    $attribute = $_product->getResource()->getAttribute('cod_available');
    $attribute_value = $attribute ->getFrontend()->getValue($_product);
    if ($attribute_value == 1)
    {?>


    <div class="two">?<p class="three"><?php echo "Available";?></p><?php 
     }

    else
    {?><i class="one"></i>


    <p><?php   echo " Not Available";
    }
    ?>
    </p>

Your Answer

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