Archived topic
WooCommerce sort buttons
2 replies · Started by MaksymPS on May 19, 2016
Hi,
I need your help!
WooCommerce includes several options in the core plugin for sorting products on the Shop page. By default, you’re given 6 options. All of them start from English sorting, then Russian. I started to search how to do the opposite, and found the next: here is the link.
I started to put products started with English letters to the end, and noticed that all my products sorting by random.
Then I found code and paste it into functions.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'] = 'name';//поле по которому сортируем
$args['order'] = 'ASC';//по возрастанию (ASC) или убыванию (DESC)
$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'] = 'Сортировка по названию (по возрастанию)';
return $sortby;
}
Now I'm using this plugin for filter products (planning to buy this one).
And when you on the shop page, sorting is good, but when you click on any of filter checkbox or go to the next page - it's random sorting again...
I found Sort Items Alphabetically Using jQuery but not sure - will it help?
Even if this will help, can you help me please, how to make alphabetical sorting first Russian, then English...
Thanks in advance!
Hi there,
I'm afraid I don't know enough about how WooCommerce does the sorting, so I'm not much help.
Have you tried asking in their support forum? They have a whole team dedicated to this sort of thing.
Let me know :)
No, I haven't. I was hoping that you could help.
Okey, I go there. Any way thanks for an advice :)
