How to rig an IK leg with 2 knee joints
So, here is the solution we've found:


Create a controller for your foot, deparent it, parent the foot to this controller.
Choose this controller as the Target of your calf's IK.
The Chain Length of your calf's IK constraint must be 2.
Create a new controller at the bottom of your bone D.
Parent this second controller to the foot controller (Keep Offset).
Parent the pole target of your calf to the foot controller (Keep Offset).
Add a Copy Location constraint to your foot so that it sticks to the calf.
Add a Damped Track or an IK constraint to the bone D and choose the new controller as your Target


Also note that you can limit the IK bones rotations in Properties > Bone > Inverse Kinematics, or with a Limit Rotation constraint, depending on the bones and the chosen solution.