Weirdly, I did try UDF before, but it failed back then, I don't remember why. Now I think I might not have added the UDF to the subscription DB, only to the publishing DB.
Anyway now it does work as desired!
Thanks a lot for nudging me to retry the UDF option.