• Resolved jed30

    (@jed30)


    Hi, I would like the ajax search results that appear to be in menu order, not in the order it’s in now. Is this possible? Thanks!

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

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

    (@mihail-barinov)

    Hello,

    Please try to use following code snippet

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

    Regards

    Thread Starter jed30

    (@jed30)

    That is working wonderfully, but the order needs to be reversed. Right now it’s showing Course #3, Course #2, Course #1, etc.

    Plugin Author ILLID

    (@mihail-barinov)

    Please change line

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

    to

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

    Thread Starter jed30

    (@jed30)

    THANK YOU!!! It’s working great. ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Ordering search results by menu order’ is closed to new replies.