They were foolish in that they did not consult each other before deciding on what gifts to give. For this reason, Della sold her magnificent hair for a watch chain to put on Jim's fob (a family heirloom), which he unfortunately sold for a turtleshell hair clasp (which evidently Della couldn't use anymore).
They were wise (therefore, like the Magi) in that they gave in the true spirit of sacrifice. Their "useless" gifts were the demonstration of their love for each other, which was beyond price. O. Henry uses this contrast to make the point that sincere giving is a state of the heart, which in itself is more precious than any object which can simply be bought or sold.
The juxtaposition of two opposites which at first glance seem to contradict each other (but really don't upon closer scrutiny) is a literary device called an oxymoron. Calling Della and Jim both "foolish children" and "the Magi" is an example of this.
See the reference below for further insight into other elements of the "O. Henry formula."