Limit facet choices based on current term archive

<?php

add_filter( 'facetwp_facet_where', function( $where_clause, $facet ) {
    if ( 'categories_checkbox' == $facet['name'] ) {
        $name = $facet['name'];
        $tax = str_replace( 'tax/', '', $facet['source'] );
        $facets = FWP()->facet->facets;

        if ( isset( $facets[ $name ] ) ) {
            if ( ! empty( $facets[ $name ]['selected_values'] ) ) {
                $term_slug = $facets[ $name ]['selected_values'][0];
                $term = get_term_by( 'slug', $term_slug, $tax );
                if ( isset( $term->ID ) ) {
                    $where_clause .= " AND f.parent_id = '{$term->ID}'";
                }
            }
        }
    }
    return $where_clause;
}, 10, 2 );