You must have limited comprehension skills.
The law says,
"It is unlawful for a person to distribute any type of campaign literature or place any political posters within five hundred feet of any entrance used by the voters to enter the polling place.."
Wearing a hat is not
distributing anything. It goes on to state that you also cannot hand out material or hang posters. Read and learn.
Here are two more official sources which show that in South Carolina, you can wear what you want when you go to the polls to vote in SC...
(2020 version, the distance restricting campaigning is now 500 feet, not 200)
Virginia law is similar but more clear...
law.lis.virginia.gov