I experienced this problem this week. My phone is a 7+ that I've had for 16 months so definitely out of warranty. Two days ago I suddenly couldn't use my apple headphones (not bluetooth), I couldn't hear out of the earpiece and the speakerphone and add call options were greyed out. I tried several different things: upgrading to 11.4, restarting several times, backing it up and wiping it out, and restarting over and over (even though this now took twice the time it took before the issue).
I contacted the apple support via chat online, they then set me up with a genius bar appointment. The guy at the store knew what it was immediately. They have to run a diagnostic on your phone to make sure there are no other damages to it and if it checks out they will exchange your phone for a refurbished model. I was lucky that they had mine in stock, and I didn't have to pay but the cost is $349 if for some reason they try to charge you.