WooCommerce – change the default sort to “relevancy”

<?php

add_action( 'pre_get_posts', function( $query ) {
    $using_sort = isset( FWP()->facet->http_params['get'][ $prefix . 'sort' ] );
    if ( 'product_query' == $query->get('wc_query') && ! $using_sort ) {
        $query->set( 'orderby', 'post__in' );
        $query->set( 'order', 'ASC' );
    }
});