FacetWP – order facets by WooCommerce term order

<?php

function fwp_term_orderby( $orderby, $facet ) {
    if ( 'YOUR_FACET_NAME' == $facet['name'] ) { // Replace "YOUR_FACET_NAME"
        $term_ids = get_terms( array(
            'taxonomy' => str_replace( 'tax/', '', $facet['source'] ),
            'fields' => 'ids',
        ) );

        if ( ! empty( $term_ids ) && ! is_wp_error( $term_ids ) ) {
            $term_ids = implode( ',', $term_ids );
            $orderby = "FIELD(f.term_id, $term_ids)";
        }
    }
    return $orderby;
}

add_filter( 'facetwp_facet_orderby', 'fwp_term_orderby', 10, 2 );