'How can I hide products from the shop after certain time out of stock?

I'm managing a big store that has a really big rotation of different products. We get new products, after a few days they sell out and then we may or may not receive them ever again, it's ever changing.

I'd like to keep the products in the store for a few days after they sold out and then either hide them from the store or just unpublish them as a draft so the store doesn't fill with out of stock items.

I saw this question before in This Post and tried to use it but unfortunately it's not working for me.

If someone has seen something similar or is interested in similar functionalities or if someone can point me to any direction to resources that can help me solve this please reach out.

Any help would be greatly appreciated



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source