Add a sort by product name option to the default WooCommerce sorting

Contents

Build your own WordPress Support Plan

Expert, yet affordable WordPress support & maintenance plans.
View our pricing

We often get asked this question and see a lot of clients using a plugin to achieve this simple request. How do you add a ‘Sort Alphabetically’ option to the standard WooCommerce product sorting drop-down option?

There are two ways that we can use to add Add a sort by product name option to the default WooCommerce sorting, both methods are explained in detail below.

Using Plugin

Extra Product Sorting Options for WooCommerce provides options that extend the default WooCommerce order-by options on the shop page. You can optionally set a new name for the default sorting (helpful if you’ve used this to create a custom sorting order) and can enable up to 5 new sorting options: alphabetical, reverse alphabetical, on sale, review count, and availability product sorting. You can also remove core sorting options, or remove the sorting dropdown completely.

image 27

Features

Includes options to:

  • rename default product sorting (i.e., change to “Our Sorting”)
  • enable alphabetical product sorting
  • enable reverse alphabetical sorting
  • enable on-sale sorting (note: works only for simple products)
  • enable sorting by inventory/availability
  • enable sorting by review count (most reviews to least)
  • remove core sorting options

Rename Default Sorting

You can customize your product sorting order on your shop pages – here’s a handy tutorial to do so. However, many shop admins like to then rename this from “Default Sorting” to something more descriptive, such as “Our Sorting” or “Our Selection”. You can optionally enter a new name for this sorting order if desired.

Adding Sorting Options

When you create a customized sorting order, you lose the ability to sort products alphabetically. This plugin gives you the ability to add new sorting options to list products by title A to Z or in reverse order (Z to A).

Want to show items with the highest stock first? You can enable sorting by availability, which will enable sorting from high stock to low stock (See FAQ for more details). You can also sort by the number of product reviews.

You can add the option to sort items by sale status – there’s a sorting option to show “On Sale” items first in the shop catalog. Please note that only simple products can be sorted by sale status, and variable products will display mixed with non-sale products.

Remove Sorting Options

You can remove the core sorting options as well! If all sorting options have been removed, the sorting dropdown will become hidden on shop pages.

Using Coding

This is a very feature to add and all it requires is a bit of PHP, you can add the functionality needed to your theme functions.php file if you are using a child theme. You can also add it as a Snippets using the Code Snippets plugin.

The function needed
This function is pretty simple and adds the option to sort products by name alphabetically, in ascending order.

/**
 * Sort by name function by WP Helper
 *
 * https://wphelper.io/sort-alphabetically-option-default-woocommerce-sorting/
 */
add_filter( 'woocommerce_get_catalog_ordering_args', 'wphelper_woocommerce_get_catalog_ordering_args' );
function wphelper_woocommerce_get_catalog_ordering_args( $args ) {
    $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );

    if ( 'alphabetical' == $orderby_value ) {
        $args['orderby'] = 'title';
        $args['order'] = 'ASC';
    }

    return $args;
}

add_filter( 'woocommerce_default_catalog_orderby_options', 'wphelper_woocommerce_catalog_orderby' );

add_filter( 'woocommerce_catalog_orderby', 'wphelper_woocommerce_catalog_orderby' );
function wphelper_woocommerce_catalog_orderby( $sortby ) {
    $sortby['alphabetical'] = __( 'Sort by name' );
    return $sortby;
}

Once you add this function to your theme functions.php file or code snippets you will now have the option to sort the products by name on the WooCommerce shop pages.

If you get stuck with this guide you can hire us to add this for you.

Conclusion

We can able to add a sort-by-product name option using custom coding and by using a plugin approach.

For more information on WooCommerce sorting, let us help you accordingly, from start to finish, with one-Time fixes, custom plans, or monthly routines for your WordPress website.

Written By
Adam Haworth
Founder of WP Helper.
You will also like these articles

Relax Knowing Your WordPress Site Is Secure & Running Smoothly 24/7

Let us manage your WordPress site, everything from security to updates will be taken care of. Support plans also come with dedicated support so we can do anything from adding content to customising your site for you.

Same Day Professional WordPress Support

Get WordPress Support Today

Need help with a single WordPress problem, today? We can help with anything from adding analytics tracking code to site hack recovery. Full money back guarantee on all jobs.

1. Submit a Support Request

Use our support ticket form below to send details of your problem to our developers.

2. Get a Quote

We will review your request and provide a quote within 24 hours (but usually within a few hours).

3. We fix your WordPress problem

Our team will begin fixing your WordPress problem the same day.

4. 100% Money Back Guarantee

If we can’t fix the problem for the amount quoted we will refund you 100%.

  • Do you have a screenshot of the issue or have a copy of the theme or plugin that is at fault? If you want to upload php, html or css please zip first.
    Drop files here or
    Accepted file types: jpg, jpeg, png, pdf, zip, gzip, rar, doc, txt, Max. file size: 15 MB, Max. files: 10.