Yes, but it's not really worth it since you will be adding shaving cream. The lotion, shaving cream, and foaming hand wash will make the glue look white, instead of clear. If you're asking because that's all you have on hand, then yes, it will work.
Hot glue would not work well for fabric. Fabric glue would work to make the hat without sewing, though the pleats may be a little tricky, and the hat would...