The Christmas Candy Cane originated in Germany about 250 years ago. They started as straight white sugar sticks.
A story says that a choirmaster, in 1670, was worried about the children sitting quietly all through the long Christmas nativity service. So he gave them something to eat to keep them quiet! As he wanted to remind them of Christmas, he made them into a 'J' shape like a shepherd’s crook, to remind them of the shepherds that visited the baby Jesus at the first Christmas. However, the earliest records of 'candy canes' comes from over 200 years later, so the story, although rather nice, probably isn't true!
Sometime around 1900 the red stripes were added and they were flavored with peppermint or wintergreen.
Sometimes other Christian meanings are giving to the parts of the canes. The 'J' can also mean Jesus. The white of the cane can represent the purity of Jesus Christ and the red stripes are for the blood he shed when he died on the cross. The peppermint flavor can represent the hyssop plant that was used for purifying in the Bible.
Taken from https://www.whychristmas.com/customs/advent.shtml.