Answer:
In the world of buying or selling animals, one would not buy an animal that is hidden, right? In the 19th century, a poke was a sack or a bag. So buying a pig, in this case a piglet, inside a sack would not be a good idea because you could not see the animal.
A related expression in fashion is poke bonnet, a cloth hat with a gathered roomy back...which was frequently used to carry small items from market. The poke bonnet had sturdy ties to attach it to the head, which could be tied as a handle to use as a carry strap for the bonnet's use as a sack.
It means to buy (receive or obtain) something unknown because its true identity is concealed.
A poke (compare 'pouch') is an English dialect word for a sack or bag.
If you went to a market to buy a (small?) pig, and the market trader had one already tied in a sack ready for sale and taking away, and if you bought it and went away without actually checking the contents, you would have bought a pig in a poke, OR NOT!
You would not know what you had really bought until you had actually opened the sack. If you waited until you got home before doing this, and it wasn't the pig you had been expecting, you would be very disappointed and angry, with yourself and with the trader.
If you then went back to the trader and said 'Hey! There wasn't a pig in this sack!" He might say "Well. There isn't now! But there was one in there when I gave it to you!"
You had bought a pig in a poke! Not a good idea!
Lesson: Buyers beware! Always check the genuineness of what you are buying before parting with your money.
But why say 'a pig in a poke'? It runs off the tongue much easier than saying 'a pig in a tied sack.' Furthermore, the imagery is much stronger with 'a pig in a poke' than simply referring to having bought something without properly checking what was inside the wrapping.
To "buy a pig in a poke" is to purchase something without being able to inspect it first. "Poke," from the French poche, means a bag.