Home > WooCommerce > How to Change Default Product Sorting in WooCommerce?

How to Change Default Product Sorting in WooCommerce?

If you want to change the default product sorting option in woocommerce then you are in right place. In this tutorial, we will learn ways to change the default product sorting option in woocommerce.

As you know woocommerce has a category page and an archive page to show the products, and these pages use the default alphabetical sorting. WooCommerce comes with four default sorting options such as popularity, average rating, latest, price, etc. The users can select one of them and see the product based on the selected sorting filter option.

Suppose you have some specific products that you want to list at the top of the category page. Then you can do this by changing the default sorting of products to others or you can add the menu order on the product page. You can also do this by woocommerce hook. We will all cover these ways to change the product sorting in this tutorial.

We have four methods to change the default product sorting option in woocommerce. Let’s see one by one, how we can do that.

Method 1: Product Sorting Tab

In this method, I will show you how you can change the default sorting of woocommerce products. This method is very simple you just have to drag and drop the product on their respective number.

Follow the below simple steps to achieve this.

  • Go to the Products menu in your WordPress admin area and you will see the filter options tab like ‘All’, ‘Published’, ‘Draft’, ‘Trash’, ‘Sorting’. So click on the Sorting tab link. See the following image for reference.

    WooCommerce Product Sorting Tab

  • Here you need to simple hold the product that you want to move and release where you want to show that product. It is very simple by drag and drop. See the following image.

    WooCommerce Sorting Product Drag Drop

  • Now you will see the products on shop page that you just change the order of product will shown at the list of top.

Method 2: Product Data Metabox – Advanced Tab

In this method, we will change the default woocommerce product sorting using the menu_order value. You have to add menu_order option value for each product or you can only add for those which you want to show on the top of the list.

The default value of the menu_order text option is blank, so you can add the number in this field according to product priority. The lower number will be on high priority, which means products of lower will be showing at the top of the list on the shop page or archive page.

Also read: How to Add Custom Text After or Before Product Title on Shop Page?

Note: The number could be negative or positive. The negative number’s product will be shown at the top. If product A has -1 menu_order and product B has 0 menu_order then product A will be shown at first.

Follow the below steps to change the default product sorting with menu_order value.

  • Go to the Products menu in the admin area. You will see all list of products, so edit any product.
  • In the Product edit page, you will see the Product data metabox where you can add all the information of product.
  • Here you will see the Advanced product tab in the product data metabox. So click on it and here you will see the Menu Order text box.

    Product Data Metabox - Menu Order Option

  • Change these Menu Order option value of product that you want set on high priority and then update the product. Now you will see your product will be on top list on the shop or archive page.

Also read: How to Hide a Specific Product from Shop Page or Archive Page?

Method 3: WooCommerce Product Catalog

In this method, we will see how to change the default product sorting using Product Catalog options in woocommerce settings. The option you can find in the Customize under Appearance menu.

Using the product catalog option you can change the default sorting option with other default options like Popularity, Average Rating, Latest, and Price. These are the default options that come with woocommerce. You can also add the new custom option in this sorting filter.

Follow the below steps to change the default sorting with product catalog options.

  • Go to Appearance menu in admin area then click on the Customize menu option.
  • Here you will find the WooCommerce setting tab, so click on it. After that, you will see the Product Catalog option tab, click on it.
  • Then, there is a display setting for change the default sorting behaviour with the default sorting options.

    WooCommerce Product Catalog Sorting Option

  • So select the sorting option for product and then save the changes by clicking on the Publish button.

Method 4: Using WooCommerce Filter Hook

As you know woocommerce is very scalable and customizable, and you can easily make changes in woocommerce using the desired action/filter hooks.

So in this method, we will make a hook function to change the default sorting of product in woocommerce. We will use the child theme’s functions.php file for any customization.

Recommend tutorial: How to Create a Child Theme in WordPress?

See the following code or add in your functions.php file but change the sorting option as per your requirements.

In the above code, we use a woocommerce_default_catalog_orderby filter hook and make a function to change the default product sorting dynamically. We set up the sorting option as ‘popularity’ and you will see on the shop page your product will be shown as popularity.

There are more default options that you can set up in the above function code. See the following list are:

  • menu_order: This is default option, it will sort menu order value first then by product name
  • popularity: It will sort by number of sales
  • rating: Sort by average rating of product
  • date: It will show the latest product at top
  • price: It will sort by price low to high
  • price-desc: Sort by price high to low
  • rand: It will show the product in a random order

Change the Default Sorting for a Specific Category

You can also change the sorting of products for a specific category. You just have to make a condition and return the default sorting variable. To check the product category, you can use is_product_category('category-slug') function.

Look at the following example code.

In the above example code, we make a condition for the ‘fashion’ category and sort the products of this category by price low to high. If products are not lying in this category then it will work default sort option set up in the product catalog.

Conclusion

So in this tutorial, we learned about how to change the default product sorting option in woocommerce. We learned four methods to change the sorting, Product, sorting tab, Product menu order option, Product catalog setting, and using woocommerce filter hook.

I hope you liked it, please share it with your friends so they can take reference examples of product sorting in woocommerce. And if you have any questions please ask me in the comment section.

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment