<?php
// Output only sub categories of current woocommerce product category
// See the improved example here that fixes depths:
// https://facetwp.com/help-center/developers/hooks/output-hooks/facetwp_facet_render_args/#remove-facet-choices-that-are-not-children-of-the-current-term
add_filter( 'facetwp_facet_render_args', function( $args ) {
if ( 'my_facet_name' == $args['facet']['name'] && is_product_category() ) { // replace 'my_facet_name' with the name of your facet
$current_term = get_queried_object_id();
foreach ( $args['values'] as $key => $row ) {
/* to also include current term in chocies add this to if:
&& $row['term_id'] != $current_term
*/
if ( $row['parent_id'] != $current_term ) {
unset( $args['values'][$key] );
}
}
$args['values'] = array_values( $args['values'] ); // fixes indexes
}
return $args;
});