facetwp order by acf order of choices when term order is the sort

<?php
/** use term order sort setting to sort by order of choices set in ACF field **/
add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) {
    if ( isset( $facet['source'] ) && 'acf/' == substr( $facet['source'], 0, 4 ) && 'term_order' == $facet['orderby'] ) {
        $source = str_replace( 'acf/', '', $facet['source'] );
        if ( isset( get_field_object( $source )['choices'] ) ) {
            $ordered_choices = implode( '", "', get_field_object( $source )['choices'] );
            $orderby = 'FIELD(f.facet_display_value, "' . $ordered_choices . '")';
        }
    }
    return $orderby;
}, 10, 2 );