Customise Product Sorting Options in WooCommerce – 2024

For WooCommerce store owners, providing an intuitive shopping experience is key to customer satisfaction and retention. One effective way to improve user experience is by customising the product sorting options available on your shop page. In this tutorial, we’ll walk through how to customise product sorting options, allowing customers to sort products based on criteria that are most relevant to your shop.

Prerequisites

Ensure you have administrative access to your WordPress site and that you’re familiar with editing PHP files. Consider making these changes in a child theme to preserve them during updates.

Step 1: Define New Sorting Options

Let’s start by adding a new sorting option that allows customers to sort products by popularity within a specific category. This is particularly useful if you have diverse categories with varying degrees of popularity.

Step 2: Add Custom Code to Your Theme’s functions.php File

Open your theme’s functions.php file and insert the following PHP code to customise product sorting options. This code snippet adds a new sorting option and defines how products will be sorted when this option is selected.

/*
 * Snippet: Customise Product Sorting Options in WooCommerce – 2024
* Author: John Cook
* URL: https://wcsuccessacademy.com/?962
* Tested with WooCommerce 8.9.3
*/ // Add new custom sorting options add_filter('woocommerce_catalog_orderby', 'wcsuccess_add_custom_sorting_options'); function wcsuccess_add_custom_sorting_options( $options ) { $options['popularity_category'] = __('Sort by popularity within category', 'woocommerce'); return $options; } // Apply custom sorting method based on the new option add_action('woocommerce_product_query', 'wcsuccess_apply_custom_sorting'); function wcsuccess_apply_custom_sorting( $query ) { if ('popularity_category' === $query->get('orderby')) { $query->set('meta_key', 'total_sales'); $query->set('orderby', 'meta_value_num'); $query->set('order', 'desc'); } }

Explanation of the Code

  • Custom Sorting Option: The wcsuccess_add_custom_sorting_options function adds a new sorting option to the dropdown menu on the WooCommerce shop page. The option is labelled as “Sort by popularity within category.”
  • Sorting Logic: The wcsuccess_apply_custom_sorting function defines what happens when the new sorting option is selected. It sorts products based on their sales data, displaying the most popular items first.
  • Meta Key Usage: The use of meta_key for sorting by total_sales ensures that products are sorted based on their actual sales performance.
See also  How to Programmatically Schedule Price Changes for Products in WooCommerce - 2024

Step 3: Test the New Sorting Option

After implementing the custom code:

  • Visit your WooCommerce shop page.
  • Use the sorting dropdown to select the new “Sort by popularity within category” option.
  • Verify that products are sorted according to their sales figures, showing best-sellers first within any given category.

Customising Further

You can customise this further by adding more conditions or sorting based on other criteria like stock status, date added, or custom attributes. Each additional sorting logic will enhance how customers interact with your product listings, making your store more user-friendly.

Conclusion

Customising product sorting options in WooCommerce allows you to tailor the shopping experience to meet both the business and customer needs. By implementing “Customise Product Sorting Options”, you provide your customers with a more relevant and practical way to browse products, which can lead to increased satisfaction and sales.

See also  Move email address field to top of Woocommerce checkout page

Always ensure to test any changes on a staging site before applying them to your live site to prevent any disruptions in the customer shopping experience. This tutorial on how to customise product sorting options should help you get started on making your WooCommerce store even more successful and customer-centric.

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Scroll to Top
×