hi,
Is there a setting to show out of stock products at the end of the store or category pages?
regards,
Recep
This topic has 3 replies, 3 voices, and was last updated 1 months, 1 weeks ago ago by Tony Rodriguez
hi,
Is there a setting to show out of stock products at the end of the store or category pages?
regards,
Recep
Hello @Recep,
This request would require customization code and therefore falls outside the scope of our standard support.
However, you may try using one of the following code examples:
function order_out_of_stock_products_last( $query ) {
if ( $query->is_main_query() && is_shop() || is_archive() && ! is_admin() ) {
$meta_query = $query->get( 'meta_query' );
$meta_query[] = array(
'key' => '_stock_status',
'compare' => 'EXISTS'
);
$query->set( 'meta_query', $meta_query );
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'ASC' );
$query->set( 'meta_key', '_stock_status' );
}
}
add_action( 'pre_get_posts', 'order_out_of_stock_products_last' );
Or:
add_filter( 'woocommerce_products_widget_query_args', function( $query_args ) {
// Make sure the stock status meta exists
$meta_query = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array();
$meta_query[] = array(
'key' => '_stock_status',
'compare' => 'EXISTS',
);
$query_args['meta_query'] = $meta_query;
// Order by stock status first, then by date (optional)
$query_args['orderby'] = array(
'stock_status' => 'ASC',
'date' => 'DESC',
);
$query_args['meta_key'] = '_stock_status';
// Use meta_value sorting explicitly
$query_args['orderby'] = array( 'meta_value' => 'ASC', 'date' => 'DESC' );
return $query_args;
}, 999 );
Best regards,
8Theme Team
Dear Recep,
We really appreciate your time and engagement within the WordPress & WooCommerce community
Your feedback drives every improvement we make in XStore — helping us deliver a smoother and more flexible experience with each update.
💡 Share your quick thoughts — it takes less than a minute!
Your input makes a real difference.
Topic closed.
The 8Theme Team
The issue related to '‘Is there a setting to show out of stock products at the end of the store or category pages?’' has been successfully resolved, and the topic is now closed for further responses