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?
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.site/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.
is there a way to make this the default sorting option?