"lock" item slots in barrel for custom gui

So, I'm making a "shop" block. I need to "lock" all the item slots. All the items have a custom_data{"tag":"trade_station_ui"}.

I know that you can't LOCK item slots. I just need to figure out how to check the 20 slots in the barrel to see if they have the tag. I have had no luck finding a command that worked. I also need the command that gives the player back an item if its in the incorrect slot.

Continue to help post