They buried them, the exact process of how that worked varied a little between the Germans, the Allies and the Soviets but in very general terms, here's how it worked.
Let's assume you're an infantryman from sunny california. You've answered your nations call, you've gone through basic, earned your rifleman's badge, you're ready to eat barbed wire for breakfast and ask for seconds just to get to kill a nazi. You've waded ashore at Omaha Beach, survived the murderous fire and made it past the entrenched defenders. You've just pushed through a hedge row outside of Longueville when suddenly your chest burns like fire, your knees give out instantly and you hit the french soil face first. Someone roars "Medic!" but it all sounds really far away, even muted.
Someone rolls you over and clasps your hand. "Hang in there, you're going to make it!" he calls. "Medic!" he shouts again over the sound of small arms fire. Someone grabs your jacket and drags you back through the hedge row where a man with a red cross on his helmet looks down at you. Everything is so fucking cold all of a sudden. Everything except your chest which burns like the sun.
From here on your story can take two different paths. On one path your might die at no less than half a dozen places and odds are you'll never be the man your were again. It's a path that requires a lot of luck, fortunate circumstances, fortitude and will to walk. The other path is a lot shorter.
The short, wide path.
You don't get to walk the long hard path that involves the risk of dying and months of seemingly endless agony. The bullet missed your heart but hit one of your coronary arteries. Within a minute you go into shock, you tremble uncontrolably as your BP plummets and your lungs fill up with blood. You give a final spastic cough that produces a spray of blood, then you die. Your platoon pushes on into Longueville to take out the German AA there, no one really has time to find out what happened to you until that night.
The medic eventually leaves the field aid station where you died after those he managed to stabilize have been medivaced to the beach and eventually a hospital ship. He reports your location to the mortuary affairs team. The mortuary affairs team bring a detail of soldiers, in your case unassigned replacements, and move your body to a field somewhere out of sight along with hundreds of other dead. Here they identify you, pack your personal belongings into a small bag and wrap your up in a blanket. An interment form is filled out and passed on, The next day and engineer company arrive and begin the process of building a cemetary. They bring a few german POWs with shovels and picks. Your name is written on a board and you are buried 6 ft deep in french soil.
Back in England someone eventually gets the information that you're dead, packs what personal belongings you had left there and ship them stateside along with the bag of your personal effects recovered by the Mortuary affairs team. Your family will eventually get a visit from an officer and an army chaplain who deliver a letter briefly outlining how you gave your life in service of your country. Eventually, after the war, your remains might be moved to one of the big cemetaries.
The narrow path of pain.
Through some miracle or divine intervention the bullet shatters on your rib sending fragments into your lung but misses major arteries. The medic injects your with morphine which takes the burning feeling from levels comparable to the sun down to a much more managable level of 'someone has lit a fire on your chest'. You get a sloppy bandage, another shot of morphine and eventually a truck arrives to take you to the beach. If you die here, you go back to basically what is detailed above. If you live, you get to move on and be carried back to an LCM just like the one your jumped out of just after dawn. It takes you back to a hospital ship a mile or so off the coast. This is the first time an actual doctor takes a look at you, concludes that you are drowning in your own blood, albeit slowly, and decides that you need surgery.
You get stripped, washed and rushed to an operating room where an exhausted team of doctors and nurses to their very best to dig the bullet fragments out of your lung, seal it, reinflate it and patch you up. If you die you'll get swept into a sheet and buried at sea, in every other respect it's the same as above. But you don't die. You wake up in a hospital ward. You're eventually unloaded in England again where you're taken to a real hospital. They conclude that you have sepsis due to a piece of cloth pushed into the wound. Back to surgery you go!
If you die here you get buried in England, the other details are again, as above. But you don't die. You wake up yet again, feeling weak as a newborn calf. Congratulations, you may now recover enough to be put on a ship back home where you may begin the long process of recovering from a severe chest wound. You will never serve in the army again but at least you're alive. Huzzah!