Look at my code… How do expand to multiple categories?
-
04-10-2020 - |
Pregunta
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; ?>
Solución
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); ?>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange