Woocommerce multiple parameter sorting

I try to sort my product on the archives pages of woocommerce.

I want to display first:

Read More
  • Product on sale
  • Product with category id 34
  • Product with custom field “my_custom_field” with value “1”

I found that but it’s doesn’t work for me and it’s just to put sale on top. I want to put sale and specific category and specific custom field value:

function my_modify_query( $query ) {

if ( is_post_type_archive('product') && is_main_query() ) {
    set_query_var( 'orderby', 'meta_value_num' );
    set_query_var( 'meta_key', '_sale_price' );
}
}
add_action( "pre_get_posts", "my_modify_query" );

Someone can help me ?

Related posts