I have found the answer in another thread. Passing variables through locate_template
Essentially the WordPress function get_template_part changes the scope of the variable $user_choice
. PHP default behaviour when using include() is that the variable from the current script is still available in the included file. However because get_template_part()
is a function any variables in that template file now have local scope. Hence the errors.