Magento how to do selected single product should be purchase alone?

I have one restricted product, here how to do selected single product should be purchased alone? No other products are eligible to add add-to-cart if this product available in the add-to-cart, same if other products available in add-to-cart this product not eligible to add add-to-cart. How to achieve this in Magento?

Workout-> https://gist.github.com/aveevan/909d4481bc8fe663acc0799e90f2aca7 not working.