Magento 2. How to add condition into phtml using php included into special category ID?

In phtml template file ( using php ) in Magento 2 ( Adobe commerce ) sometime you want to add condition:

If included into special Category ID or all subdirectories of it:

use this code:

$categoryIds = $this->getProduct()->getCategoryIds();
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $_objectManager->create('Magento\Catalog\Model\Category')->load(341);
$isCollection = false;
$requestPath = '';
$categoryName = '';
foreach ($category->getChildrenCategories() as $child) {
if (in_array($child->getId(), $categoryIds)) {
$isCollection = true;
$requestPath = $child->getRequestPath();
$categoryName = $child->getName();
}
}
<?php if (!in_array('8', $_product->getCategoryIds())) : ?>
<style type="text/css">
    .mp-price-note-flooring {
        display: none;
    }
</style>
    <?php endif; ?>

Метаданные статьи

Идентификатор статьи:
103
Категория:
Дата добавления:
25.07.2023 18:41:19
Просмотры:
126
Рейтинг (Голоса):
(0)

Связанные статьи