GET FREE VERSION GET THE PRO VERSION

Version 3.08: Some changes regarding products custom sorting

Brief summary of this article:

Speed-up search results page

The most important change is a significant increase in the loading speed for pages with search results. Before that update some users with a large total number of search results ( more than 100 results per search query ) could struggle with too long loading time. Now this issue is fixed and page loading time will be no longer that the same time for ajax live search results.

All changes applied automatically and you don't need to make any extra steps here.

If you want to load those pages even faster - you can do this by decreasing the number of products per page and the total number of search results.

To do that please open the plugin settings page -> General tab and scroll down to Search Results Page section. Inside it change the values for Max number of results and Results per page option. Pay more attention to the second one as it has the highest impact on loading speed.

Search results page options

Search results page options

New code snippets for custom products sorting

Some important changes for users that are using custom code snippets to sort products search results. It includes sorting by price, date, stock status, quantity, etc.

Example: old code snippet for sorting products by price:

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

New code snippet starting from 3.08:

add_filter( 'aws_search_results_products_ids', 'my_aws_search_results_products_ids' );
function my_aws_search_results_products_ids( $products ) {
    usort($products, function ($a, $b) {

        $price_a = get_post_meta( $a, '_price', true );
        $price_b = get_post_meta( $b, '_price', true );

        $price_a = intval( $price_a ) * 100;
        $price_b = intval( $price_b ) * 100;

        if ( ! is_numeric( $price_a ) || ! is_numeric( $price_b ) ) {
            return 0;
        }
        if ($price_a == $price_b) {
            return 0;
        }

        return ($price_a < $price_b) ? -1 : 1;
    });
    return $products;
}

As seen - we are now using the new aws_search_results_products_ids filter to sort products IDs. Main difference with the old aws_search_results_products filter is that the new one returns only product IDs and not the full product arrays with data.

Large list of examples of code snippets to sort products by different parameters can be found here: Ordering Search Results.

Replacing some plugin hooks

Old filter aws_products_search_page_filtered is replaced with aws_search_page_products_filtered.

apply_filters( 'aws_search_page_products_filtered', (array) $products );

Filter array of products IDs after applying filters on the search results page.

Parameters

  • $products (array) Product IDs

Also aws_products_order filter is replaced with aws_search_page_products_order.

apply_filters( 'aws_search_page_products_order', (array) $products, (string) $order_by );

Filter array of products IDs after applying order rules inside the search results page.

Parameters

  • $products (array) Product IDs
  • $order_by (string) Value of order by rule

Comments

Download free version

Download free version from wordpress.org repository.

Purchase pro version

Read about differences between free and pro versions here.