Answer the question
In order to leave comments, you need to log in
Why are the products sorted incorrectly (ASC)?
Good evening! In a standard woocommerce product output loop, ASC sorting looks like this:
teatro no.1
teatro no.10
teatro no.2
This is the name of the products, and for some reason the system thinks that 2 is greater than 10. I can basically guess why, but I don't know for sure, because I'm not familiar with the ASC DESC sorting principle.
Answer the question
In order to leave comments, you need to log in
because in this case it will first sort by the first character in the text, then by the second.
by the way - crutch
ORDER BY LENGTH(product), tovar
And on what property at you there sorting? If one of the meta, then meta_value_num should solve the issue:
function custom_woocommerce_catalog_orderby( $args ) {
$args['meta_key'] = '_price';
$args['orderby'] = 'meta_value_num'; // работать со значениями как с числовыми
$args['order'] = 'asc';
return $args;
}
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_catalog_orderby' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question