You could use the Catalog API and check through that if the item is a hat, hair, etc. I can’t tell more about this API as I haven’t dove into it in the past nor am I going to do that anytime soon. Hopefully the article helps.
Another way would be looking at this thread as it’s an similar issue and is handled differently by checking attachments