We are not told exactly when or where the story takes place. However, we can do know that it is not set anywhere it the distant past or future relative to the date that O. Henry wrote it (which was 1906). We can get some clues about this from the story.
Mostly, we can tell from the technology and the money values and (for those who know about such things) the language used that this is somewhere around the turn of the century. The two of them have an apartment with an electric buzzer, so there is electricity. But Della has to use gas to heat her curling irons. The apartment costs $8 per month. All of that tells us about when the story is set.
The eNotes summary says it is presumed to be set in New York. This is because of the reference to Coney Island and because Della saw the combs in a shop on Broadway.
The setting is an apartment in New York city in an apartment of meager means. New York is not directly mentioned. However, Coney Island which is in New York is mentioned in the text. Coney Island is a very famous amusement park. In addition, the writer was living in New York at the time that he wrote "The Gift of the Magi." There is also mention of Della having peered into Broadway window indicating the location is in Manhattan and runs through New York City.
"before he takes a second look at me, he will say I look like a Coney Island chorus girl."
Jim, the husband in the story has no fob chain for his watch, so Della cuts her hair to enable her to have the money to buy one. Fob Chains, worn by gentlemen in the early 1900's was a common decoration. The cost of the couple’s flat, apartment is only $8 but it is a struggle to pay it. In addition, the story discuses that at one time they were faring a little better but now Jim's salary has decreased.
"Now when the income had was shrunk to $20"
The story was published in a New York City newspaper in 1905. This makes me believe that the timeline in the story was around the same.