skip to Main Content

I’m trying to achieve the following in Magento (1.9.2) in a phtml file:

I would like to display certain html on the product page only if the product is (also) in category id 350.

The product is in many categories. I don’t want to show the html when the product is viewed necessarily from a specific category path.

So someone can visit the product page on domain.com/productURL without getting there from a specific category.

What’s important is that if that product is ALSO (not only) in category id 350, among other categories it’s in, than show a certain div. If not, show a different div.

I’m tying to put an if statement in a phtml file that is already set up, but I don’t seem to get the if statement right.

2

Answers


  1. To check either product is in category id 350 or not, you can use the following condition in product view.phtml file

    if(in_array(350, $_product->getCategoryIds()))
    

    You can use the following code to get category id when the product has viewed from a specific category path

    Mage::registry('current_category')->getId()
    

    You can add your logic by play with these conditions.

    Login or Signup to reply.
  2. Please use below code on your theme view.phtml file

    <?php 
       if($_product->getCategoryId()==350){
         your custom here
       }
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search