I use a customized shop page in my site. There I use the "Product Loop" component of WPBakery (former Visual Composer).
I want to change the "Recent" order to make the "Out of Stock" products do not show in this case, and I tried to put
'stock_status' => 'instock',
in the code bellow, but it didn't work.
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
switch ($display) {
case 'recent':
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'stock_status' => 'instock',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
'orderby' => 'date',
'order' => 'desc',
'paged' => $paged,
'meta_query' => WC()->query->get_meta_query(),
);
break;
The result is the same with or without the line.
Another situation:
I want to change the "Top Rated" option to make the "Out of Stock" products appear at the end of the product loop. I have the follow code:
case 'top_rated':
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
'order' => $order,
'paged' => $paged,
'meta_key' => '_wc_average_rating',
'orderby' => 'meta_value_num',
'meta_query' => WC()->query->get_meta_query(),
'tax_query' => WC()->query->get_tax_query(),
);
break;
I would need to use a query with 2 arguments, the top rated and the stock_status. How can I create the query in the code above?
My environment:
Theme Jupiter Version 6.1.1
WPBakery 5.4.5.1
WooCommerce Version 3.3.4
WordPress 4.9.4
Sorry, my knowledge in PHP is newbie...