• Resolved hgieg

    (@hgieg)


    Hello, thanks for the beautiful plugin.

    Is it possible to modify the search results to put Woocommerce products that are out of stock at the end of the listing?

    I read the documentation but didn’t find an answer.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Sumit Singh

    (@5um17)

    Hi,

    This is a nice feature. Thanks for the suggestion.
    However, it is not possible with current version but I would definitely try to add this in future release.

    For now you can add this code in theme functions.php and let me know if this works.

    /**
     * Order products by stock status.
     * 
     * @param array $args 
     * @return array $args 
     */
    function wpes_support_16872473($args) {
        if (function_exists('WPES') && is_search() && empty($_GET['orderby'])) {
            $args = [
                'meta_key'  => '_stock_status',
                'orderby'   => [
                    'meta_value' => 'ASC',
                    'date' => 'DESC'
                ],
                'order' => 'DESC'
            ];
        }
    
        return $args;
    }
    add_filter('woocommerce_get_catalog_ordering_args', 'wpes_support_16872473');

    Thanks

    Thread Starter hgieg

    (@hgieg)

    Worked perfectly.

    Thanks for the code and for considering adding this feature in a future update.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Sort by Stock’ is closed to new replies.