PrestaShop – check product category in smarty .tpl

If you need to display some block based on product’s category and you want to check for that category right in the smarty template ( e.g. product.tpl ) you can do so using this code – which as an example uses category 27 as base reference. You can easily find your category ID in admin.

{assign var='cats' value=Product::getProductCategories($product.id)}
{if in_array(27, $cats)}
.. following will only be displayed if this product is in category of ID 27
{/if}

If you for some reason can’t find your category ID, you can look for it by adding following into product.tpl

{assign var='cats' value=Product::getProductCategories($product.id)}
{$cats|@print_r}
Just reload page and you will see in which categories this product is. Alternatively you could use
{debug}
to access all smarty available variables and look in there.