Skip to content

Show Out of Stock products ONLY when a custom attribute is TRUE

We have a huge catalog of products, most of which we want to continue to have the standard setup of “When out of stock do not display product” as we currently have it setup. However, we have setup a attribute (faux_oos) which we want to use to identify certain products which should still show up when out of stock. I know there is an option in the configuration to show out of stock products, but enabling that would make ALL out to stock products which are enabled appear. How can we achieve this? I have tried creating a plugin with the following code:

<?php
namespace *******PluginCatalogModel;

class Product
{
    public function afterIsSaleable(
        MagentoCatalogModelProduct $subject,
        $result
    ) {

        if ($subject->getData('faux_oos')) {
            return true;
        }

        return $result;
    }
}

and this makes the page for the product visible, with additional code in the PHTML file which doesn’t show the “Add to Cart” button or option swatches if the product is not available, but the product will still not show up on category pages, search, or other blocks.