Is there a setting to show out of stock products at the end of the store or category pages?

This topic has 3 replies, 3 voices, and was last updated 1 months, 1 weeks ago ago by Tony Rodriguez

  • Avatar: Recep
    Recep
    Participant
    October 27, 2025 at 13:31

    hi,

    Is there a setting to show out of stock products at the end of the store or category pages?

    regards,

    Recep

    2 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    October 27, 2025 at 14:07

    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

    Avatar: Tony Rodriguez
    Tony Rodriguez
    Support staff
    October 27, 2025 at 15:51

    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

  • Viewing 3 results - 1 through 3 (of 3 total)

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

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.