• Resolved kiko1987

    (@kiko1987)


    Hi there!

    Is there any chance to sort products by SKU or another atribute?

    Many thanks in advanced!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    Yes, it is possible. But you will need to use little code snippet for this.
    To sort results by SKU please use

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

    Regards

    Thread Starter kiko1987

    (@kiko1987)

    Hi there,

    I’ve just test it but not working, instead of SKU can I sort them by product name?
    Don′t know de array por product name :S

    Thanks

    Plugin Author ILLID

    (@mihail-barinov)

    To sort results by product names please use

    add_filter( 'aws_search_results_products', 'aws_search_results_products' );
    
    function 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;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sort products by SKU or other atributes’ is closed to new replies.