How to apply custom condition before product collection loaded magento 2?

You can apply custom conditions to Product Collection before load by creating a plugin in Magento 2. Some situation in your project need to add some conditions before product collection loaded you can achieve it by below way,

In Magento\Catalog\Model\ResourceModel\Product\Collection file load() method is used for load the product collection globally.

For Apply custom condition before product collection loaded, you need to create a di.xml file for plugin definition and plugin PHP file for add your custom logic.

Under the di.xml file, You need to add plugin definition to create plugin beforeLoad( ) method.

Let’s create a simple module, Rbj_Product where Rbj is Vendor name and Product is the module name.
Our Module resides under app/code/Rbj/Product location.

Path:  app/code/Rbj/Product/registration.php

Path: app/code/Rbj/Product/etc/module.xml file,

Path: app/code/Rbj/Product/etc/frontend/di.xml

You need to create a plugin file under the below location,

Path : Rbj\Product\Plugin\Catalog\Model\ResourceModel\Product\CollectionPlugin.php