Order search results by product name alphabetically in Advanced Woo Search

Order search results by product name alphabetically in Advanced Woo Search on child sites.

Snippet Type

Execute on Child Sites

Snippet

add_filter( 'aws_search_results_products', 'my_aws_search_results_products' );
function my_aws_search_results_products( $products ) {
    usort($products, function ($item1, $item2) {
        $a = strtolower( $item1['title'] );
        $b = strtolower( $item2['title'] );
        if ($a == $b) {
            return 0;
        }
        return ($a < $b) ? -1 : 1;
    });
    return $products;
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.