Question

The following code works for one category - ID 9. How do I expand to two categories?

How shall I adjust to make it exclude category ID 9 AS WELL AS category ID 32?

<?php $showStartingAt = !$_product->isConfigurable() && $_product->getAttributeSetId() == 9 && $_product->getCategoryId() != 9; ?>
Was it helpful?

Solution

Simplest thing would be adding another comparison to the condition:

<?php $showStartingAt = !$_product->isConfigurable() && $_product->getAttributeSetId() == 9 && $_product->getCategoryId() != 9 && $_product->getCategoryId() != 32; ?>

A bit nicer and extendable would be something like:

<?php
$excludedCategories = array(9, 32); //Or other categories
$showStartingAt = !$_product->isConfigurable() && $_product->getAttributeSetId() == 9 && !in_array($_product->getCategoryId(), $excludedCategories); ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top