So I'm trying to display some content only if the product doesn't belong to a certain category. I know how to do this if the product DOES belong to the category, so I would do this:

if(in_array(354, $_product->getCategoryIds())){
    echo "<span>" . $_product->getDescription() . "</span>";

But not sure how to do this so to display the description only if the product DOESN'T belong to this category?

1 Answer 1


Just add ! before in_array:

if (!in_array(354, $_product->getCategoryIds())) {
    echo "<span>" . $_product->getDescription() . "</span>";

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.