Skip to content

How to remove only simple product not configurable and virtual product from collection when price is zero

di.xml

<type name="MagentoCatalogModelResourceModelProductCollection">
        <plugin name="beforeproductCollectionPlugin" type="VendorModulePluginCollectionPlugin" />
    </type>

CollectionPlugin.php

class CollectionPlugin
{
    /**
     * Remove product which price is less than one.
     *
     * @param Collection $subject
     * @param bool $printQuery
     * @param bool $logQuery
     */
    public function beforeLoad(
        MagentoCatalogModelResourceModelProductCollection $subject,
        $printQuery = false,
        $logQuery = false
    ) {
        if (!$subject->isLoaded()) {
            $subject->addAttributeToFilter([['attribute' => 'type_id','in' => 'configurable,virtual'],['attribute' => 'price','gt' => 0]]);
        }
        return $subject;
    }
}

I have added this result hide all product whose price is less than or equal to zero but I need condition apply for only on simple product.

Anyone please help me.