How can i conditionally load taxonomy-{taxonomy}.php template php files through functions.php

Find the solution 🙂

Code:

if ($moviewp_comments == 1) { 

add_filter( 'template_include', 'wpse_template_include' );
function wpse_template_include( $template ) {
    // Handle taxonomy templates.
    $taxonomy = get_query_var( 'taxonomy' );
    if ( is_tax() && $taxonomy ) {
        $file = get_theme_file_path() . '/templates/taxonomy-' . $taxonomy . '.php';
        if ( file_exists( $file ) ) {
            $template = $file;
        }           
    }

    return $template;
}
} else { 

}