Domanda

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; ?>
È stato utile?

Soluzione

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); ?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top