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