On a Product Page, I want to check if a Product Attribute is equal to a specific value. And then output the appropriate text.

Where I'm at so far

// Helper for Checking Product Attribute
$_product = $block->getProduct();
// Get Product Attributes
$shape = $_product->getShape();

<!-- Shape Check -->
<?php if ($shape == 'Round'): ?>
        <span>I am Round</span>
<?php elseif ($shape == 'Square'): ?>
        <span>I am Square</span>
<?php else: ?>
<?php endif; ?>


Despite checking a product that is either Square or Round, the output only displays Else. Therefore, my code isn't checking the attribute correctly.

1 Answer 1


Depends on the attribute type. For example if it's a dropdown you will get the ID.

Take a look at this for example


Try this:

$shape = $_product->getAttributeText('shape');

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.