I went through this with the boy I used to babysit for. i even had to quit because of that.He was 3,5 years old and he would hide in a closet or under a dining room table and do it. After two months of that I realized that he just loves to wear his pull ups with his favorite cartoon characters on them. He also had bowl movement problem. He told me it hurt when he goes. At first I would suggest to give him more dried fruit to it. My daughter loves to eat raisins, dried cherries and cranberries and she never has any problems going to the bathroom. She does it before she goes to sleep. she loves to sit on her potty and read her favorite bedtime stories. It's her favorite part of day
Wishing you best of luck