Order Product Results by Total Sales
SearchWP ranks search results based on how well they match the search terms. This ranking uses the weight settings you configure in your engine settings for different content fields. However, for WooCommerce stores, you might want to show products based on how many times they’ve been sold instead of just content matching.
Ordering products by total sales can help increase revenue by showing your most popular products first. This strategy puts products that customers already like at the top of search results.
Order Results by Total Sales
If you want to show product results ordered by sales numbers, you can use the code below. This method ignores the content matching and shows your best-selling products first, no matter how well they match the search terms.
This code sorts your search results by the number of sales in descending order (highest to lowest). The implementation takes complete precedence over SearchWP’s relevance algorithm, meaning that products will always be ordered by sales volume regardless of how well their content matches the search query.
Note: If two or more products have the same number of sales, their order will be determined by a secondary sort based on relevance.
Boost Popular Products While Keeping Relevance
If you want to keep SearchWP’s normal ranking but give extra points to products that sell well, you can use a different approach. This method keeps the content matching in place but pushes popular products higher in the results.
This code adds bonus points to products that have sold a certain number of times. The bonus includes a base score plus extra points based on total sales. This means popular products get higher rankings while SearchWP still considers how well products match the search terms.
Adjusting the Settings
The code includes three settings you can change to control how the boost works:
Minimum Total Sales ($min_total_sales): Set to 100 by default. This is the number of sales a product needs before it gets the boost. Change this number based on your store’s typical sales.
Bonus Weight ($bonus_weight): Set to 99999 by default. This is the base score added to products that qualify. Higher numbers give popular products a bigger advantage.
Sales Multiplier ($sales_multiplier): Set to 100 by default. This number is multiplied by the product’s total sales to add more points. Higher numbers create a bigger difference between moderately popular and very popular products.
Adding the Code
You can add the custom hooks by using a code snippet plugin like WPCode, or by creating a SearchWP customizations plugin as explained in this SearchWP documentation.
Once you add and activate the code, SearchWP will start using your new ordering strategy right away. With the boost method, products with enough sales will appear at the top of results, followed by other matching products.
Track Results with SearchWP Metrics
After you add a sales-based ordering strategy, use the SearchWP Metrics extension to see how it performs over time. Metrics show you how many clicks your best-selling products get compared to other results. This helps you understand if the new ordering is working well.
By looking at click data in Metrics, you can see if customers find what they want faster, or if they’re skipping over good products that don’t sell as much. Use this information to adjust your strategy, change the settings in the code, or try different approaches to find what works best for your store.

