$args = array(
'posts_per_page'=> -1,
'post_type' => 'product',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $cat_id,
)
),
);
$the_query = new WP_Query( $args );
$args = array(
'post_type' => 'product',
'posts_per_page' => 99,
'order' => 'DESC', // Display all post with thumbnail ID first
'orderby' => 'meta_value_num', // order by meta key value
'meta_query' => array( //query post based on meta key
array(
'relation' => 'OR', // add condition if meta key is exists or not
array(
'key' => '_thumbnail_id',
'compare' => 'NOT EXISTS' // include post without _thumbnail_id key
),
array(
'key' => '_thumbnail_id',
'compare' => '!NOT EXISTS' // include post with _thumbnail_id key
)
)
)
);