Can any body please help me to sort the featured products only using different sorting attributes like price,date in woo-commerce.
I have tried the code
function sort_by()
{
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'posts_per_page' => '-1',
'orderby' => $_POST['sorter'] ,
'order'=>'ASC'
);
$featured_query = new WP_Query( $args );
print_r($featured_query);
if ($featured_query->have_posts()) :
while ($featured_query->have_posts()) :
$featured_query->the_post();
$product = get_product( $featured_query->post->ID );
echo the_title();
endwhile;
endif;
wp_reset_query(); // Remember to reset
die();
}
add_action('wp_ajax_sort_by','sort_by');
add_action('wp_ajax_no-prev_sort_by','sort_by');
The above code works when ajax hit but it’s cannot sort the feature products according to date, price, popularity and rating.