I am interested in
December 16, 2018
December 16, 2018

How to sort Woocommerce products alphabetically?

In this tutorial, we are going to edit functions.php file. Don’t know where to find this file? No worries, we have an entire article where we teach you where to find it. Also, you can watch a video tutorial on our channel.

Woocommerce provides several options on sorting products. You can sort them by price, sales, average rating and by most recent. For some reason, it is not possible to sort them alphabetically. Well at least not without a little code.

With the short code provided below, you will be able to set the default shop sorting to “Sort alphabetically” in the Apprearance > Customize area and also, this option will be available on every page where sorting options is visible to your customer.

Locate and open your functions.php file and insert this code:


function websitetheory_alphabetical_shop_ordering( $sort_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 ) {
$sort_args['orderby'] = 'title';
$sort_args['order'] = 'asc';
$sort_args['meta_key'] = '';
}

return $sort_args;
}

add_filter( 'woocommerce_get_catalog_ordering_args', 'websitetheory_alphabetical_shop_ordering' );

function websitetheory_custom_wc_catalog_orderby( $sortby ) { $sortby['alphabetical'] = 'Sort alphabetically'; 
return $sortby; 
} 

add_filter( 'woocommerce_default_catalog_orderby_options', 'websitetheory_custom_wc_catalog_orderby' ); 
add_filter( 'woocommerce_catalog_orderby', 'websitetheory_custom_wc_catalog_orderby' );
Sign up to our newsletter