Another idea I had is to cut back and remove the foam to the concrete, the width to match the flange on your window well. Now cut a 6" wide or so strip of 1/2" plywood and screw it to the face of your window buck with the plywood covering the area where the foam was removed and overlapping onto your waterproofing a couple of inches at least. Now take some good quality duct tape such as Gorilla Tape and tape the outside and bottom edge of this plywood to your waterproofing. But before you install the plywood, mark and drill a 1-1/2" or so hole at the very top of the opening in the foam. After the plywood is attached to the window bucks, attach flexible vinyl tubing and a large funnel to this hole using the duct tape. Now get some high strength non-shrink precision grout and mix it to pourable consistency. Now slowly fill the void behind the plywood with this grout using the funnel while tapping the plywood with a hammer to insure it flows down and air pockets are removed. You might also want to cut a 1/4" or so notch in your plywood at the very top of your 1-1/2" fill hole to allow air to escape as the cavity is filled (do this before attaching the plywood). Follow the instructions on the grout bag regarding cure time and when the plywood form can be removed. You can attach your window well by drilling through the grout into the concrete and installed tap cons or anchor bolts. Another option that could be done before attaching your plywood forms to the window bucks would be to lay your plywood on your window well flanges, mark, and drill holes for anchor bolts in the plywood to match the window well mounting holes. Now set anchoring bolts in the plywood with nuts and washers on both sides of the plywood to hold the bolts in place at the proper head depth. This would need to be carefully planned and measured if using separate strips of plywood as the likelihood of getting them mis-aligned would be high.
If using the pre-set anchor bolt option, you might want to use a full sheet of plywood cut down as necessary to be slightly wider than the outside of your window wells. Now when you lay these on your window well to make a template for the mounting bolts you can screw the entire piece of plywood over the window opening insuring level placement and correct alignment of the mounting bolts to the window well.
Advantages are that no wood is used below grade, non-shrink grout in pourable consistency is stronger than your concrete, and a better seal is formed between the grout and existing waterproofing.
Once the form is removed, if any voids exist in the grout, some more grout can be mixed to a thicker consistency and placed in larger voids or RTV silicone or construction adhesive can be injected into smaller voids.
Another idea is to periodically (every 12" or so) install wood screws into the backside of your window bucks from the void formed by the removed foam. This would be done prior to installing the plywood forms. Install screws at a slight inward angle so the head of the screw can be driven just below the flush face of the foam. This will help anchor the grout to the window bucks once cured.