Support » Plugin: Advanced Woo Search » Search Result Sort by SKU (A to Z order)

  • Resolved robertpurnomo

    (@robertpurnomo)


    I successfully added below snippets so the search result is sort by SKU (Z to A order). Is there anyway to change sort by SKU to A to Z order?

    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;
    }

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

    (@mihail-barinov)

    Hello,

    Yes, just replace the line

    return ($a < $b) ? 1 : -1;

    with

    return ($a < $b) ? -1 : 1;

    Regards

    Thread Starter robertpurnomo

    (@robertpurnomo)

    It works perfectly 100%. Thank you so much ILLID. This is very helpful for our wholesale customers who only search by SKU.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.