Who gets the custody of the child if the mother is having an affair in UK?

The court care about what is in the best interest of the children and just because one parents had an affair does not mean they are unfit to parent. It can be shared custody or one get it. The court wants the children to have access to both parents. The affair will not be the thing that decides custody.