Answer the question
In order to leave comments, you need to log in
Sorting products by woocommrce attribute value?
I've been suffering for some day now ... help me finally figure it out.
dd_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'] = array(
'taxonomy' => 'pa_nominalnaya-moshhnost-kvt',
'field' => 'slug',
'terms' => 'pa_nominalnaya-moshhnost-kvt'
);//поле по которому сортируем
$args['order'] = 'ASC';//по возрастанию (ASC) или убыванию (DESC)
$args['meta_key'] = 'pa_nominalnaya-moshhnost-kvt';//по конкретному совпадению ключа
}
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;
}
Answer the question
In order to leave comments, you need to log in
You have a mess in the arguments, there are both taxonomy and meta_key, and their names are identical. What do you really have, taxonomy or metadata?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question