Is there a way to hide products that have the price at 0?
I tried with this Plugin but it shows the same all the products even those at price 0.
<?php
namespace Vendor\Namespace\Plugin;
use Magento\Catalog\Block\Product\ListProduct;
use Magento\Eav\Model\Entity\Collection\AbstractCollection;
use Magento\Framework\Exception\LocalizedException;
/**
* Class ListProductPlugin
*/
class ListProductPlugin
{
/**
* @param ListProduct $subject
* @param AbstractCollection $resultCollection
* @return AbstractCollection
* @throws LocalizedException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetLoadedProductCollection(
ListProduct $subject,
AbstractCollection $resultCollection
) {
$resultCollection->addAttributeToSelect('price');
$resultCollection->addAttributeToFilter('price', ['gt' => 0]);
return $resultCollection;
}
}
Could anyone point me to the right direction?
Thanks