Woocommerce: Show Products in Alphabetic order

Ok I know it’s might be a silly question or you may think it was asked dozen times. but either I am desperate and missed something or this is some unique problem. Anyway, I need your help.

My client wanted to show her products in an alphabetic way. All was good when I select Default Product Sorting “Custom ordering + Name”
But then something messed up.. and all alphabetic order in “Sort Products” Screen gone. Now they all shown according to their “Order” number.

Read More

Is there any way to make products return back to list in an alphabetic order?

I’d do it manually in “Sort Products” but there are about 100 products, and I am not sure when the client will add new products the problem won’t come back.

EDIT
I’ve found out that when you are using Default sorting (Custom order + Name) at the beginning all products shown by default in alphabetic order, however once you move one item out of the alphabetic order(e.g one “F” item placed in front of an “A” item) all order messed up, and follows only ordering according to product’s order number

Related posts

Leave a Reply

5 comments

  1. To expand on @Vikas_Gautam’s answer and modify it to sort by post title, you would do the following:

    add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
    
    function custom_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'] = 'DESC';
        }
    
        return $args;
    }
    
    add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
    
    function custom_woocommerce_catalog_orderby( $sortby ) {
        $sortby['alphabetical'] = __( 'Alphabetical' );
        return $sortby;
    }
    

    Take a look at the Codex for WP_Query sort parameters.

  2. <?php
    
    add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
    
    function custom_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 ( 'random_list' == $orderby_value ) {
    $args['orderby'] = 'rand';
    $args['order'] = '';
    $args['meta_key'] = '';
    }
    
    return $args;
    }
    
    add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
    
    function custom_woocommerce_catalog_orderby( $sortby ) {
    $sortby['random_list'] = 'Random';
    return $sortby;
    }
    
  3. To expand on @helgatheviking’s answer, I tried that and it sorted in (descending) alphabetical order but only if the Alphabetical option was chosen on the drop-down because of the if ( 'alphabetical' == $orderby_value ) condition.

    This is mod which sorts in ascending alphabetical order by default, the differences being the condition if ('alphabetical' == $orderby_value || 'menu_order' == $orderby_value) and $args['order'] = 'ASC'

    add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
    
    function custom_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 || 'menu_order' == $orderby_value ) {
            $args['orderby'] = 'title';
            $args['order'] = 'ASC';
        }
    
        return $args;
    }
    
    add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
    
    function custom_woocommerce_catalog_orderby( $sortby ) {
        $sortby['alphabetical'] = __( 'Alphabetical' );
        return $sortby;
    }
    

    The site I was working on has grouped products so I made sure they were alphabetical as well…

    add_filter( 'woocommerce_grouped_children_args', 'custom_grouped_children_args' );
    function custom_grouped_children_args( $args ){
        $args['orderby'] = 'title';
        $args['order'] = 'ASC';
        return $args;
    }
    
  4. $catalog_orderby_options = apply_filters( 'woocommerce_catalog_orderby', array(
            'menu_order' => __( 'Default sorting', 'woocommerce' ),
       here   ->  'title' => __( 'Sortierung nach Titel, A–Z', 'woocommerce' ),
            'popularity' => __( 'Sort by popularity', 'woocommerce' ),
            'rating'     => __( 'Sort by average rating', 'woocommerce' ),
            'date'       => __( 'Sort by newness', 'woocommerce' ),
            'price'      => __( 'Sort by price: low to high', 'woocommerce' ),
            'price-desc' => __( 'Sort by price: high to low', 'woocommerce' )
        ) );