DS would poo without difficulty in a nappy, but not at all in the loo. So I let him go back to nappies to take the pressure off and prevent constipation. When he needed a poo, he would go to the bathroom, take off his trousers and pants, poo, and call me to help dispose of the nappy and clean him up. He had to stay in the bathroom - no wandering off to watch TV or do something distracting.
Once he was comfortable doing that, he had a go at sitting on the toilet with a nappy on, and pooing that way. After a few weeks, we tried cutting a big hole in the middle of the nappy so that he was pretty much pooing into the loo, but still wearing a nappy.
We talked a bit about when he would be ready to stop using a nappy, and he told me that it would be when was in reception at school. We also talked a bit about what we would do to celebrate when he didn't need a nappy.
As time went on, the hole in the nappy got bigger until it was purely symbolic, and was pretty much just the waistband. But he wasn't ready to give that up.
The day after his last day of preschool, he needed the loo. I asked him if he counted as a reception child yet now that the summer holidays had started. He thought that he did, and managed a poo with no nappy. We watched the film he'd been promised, and ate ice cream to celebrate, and he has never had any problems since then, and he remembers his "poo party" fondly.
When he was a bit older he told me that he had been frightened of the splash of poo in the toilet bowl, and worried that he would get splashed. So it might be worth checking if that's part of the problem.
At the time, it took a lot of nerve to trust DS and let him take his own time, but looking back, I'm so glad I did it that way.