Help with product ordering with WooCommerce

How can I order the products alphabetically in the product file, and make this order the default? I have inserted the following lines of code to my child theme, but it does not work at all well, I appreciate your help!

Line of code:
//Adding Alphabetical sorting option to shop and product settings pages
function 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’, ‘alphabetical_shop_ordering’ );

function custom_wc_catalog_orderby( $sortby ) {
$sortby[‘alphabetical’] = ‘Alfabético’; // PUEDES PONER EL TEXTO QUE QUIERAS
return $sortby;
}
add_filter( ‘woocommerce_default_catalog_orderby_options’, ‘custom_wc_catalog_orderby’ );
add_filter( ‘woocommerce_catalog_orderby’, ‘custom_wc_catalog_orderby’ );

…When scrolling, the order of the products is broken for some reason that I don’t know, please help

Link of site: Tienda - Olimpo Sport


1 Like

I usualy use this.

image

ooor
image

2 Likes

Thank you very much @sinanisler for the help, but I still have a problem and that is that I would like the alphabetical order by title option to appear in the filter that I have inserted in the product file, I have not been able to solve that, if you have any ideas, welcome. !

Here is the plugin available to sort products in WooCommerce with just a few clicks