• Resolved wale2051

    (@wale2051)


    I’m trying to return in-stock products first, then the out of stock can be shown after. I’ve been looking for the function this endpoint is calling ‘?wc-ajax=aws_action’. I haven’t had any luck

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter wale2051

    (@wale2051)

    I tried this function I found in the docs but it doesn’t work

    add_filter( 'aws_search_results_products''my_aws_search_results_products');
    
    functionmy_aws_search_results_products( $products) {
    
        usort($productsfunction($item1$item2) {
    
            $product1= wc_get_product( $item1['id'] );
    
            $product2= wc_get_product( $item2['id'] );
    
            if'outofstock'!== $product1->get_stock_status() ) {
    
                return-1;
    
            }
    
            if'instock'!== $product2->get_stock_status() ) {
    
                return1;
    
            }
    
            return0;
    
        });
    
        return$products;
    
    }
    Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    Please tell me – this issue appears only for search results page or and for live ajax search results too?

    Regards

    Thread Starter wale2051

    (@wale2051)

    The issue is on the live ajax search results

    Plugin Author ILLID

    (@mihail-barinov)

    After adding this code you need to go to the plugin settings page and click the ‘Clear cache’ button. Have you done this?

    Thread Starter wale2051

    (@wale2051)

    I have been injecting the code using the Snippets plugin. Is it more effective adding to the Child theme? The function I currently have isn’t working

    Plugin Author ILLID

    (@mihail-barinov)

    In fact it doesn’t matter how you add code snippet – via theme file or code snippets plugin. Results should be the same.

    Strange that it is not working for you. Please tell me – are you using any other code snippet to customize search results output?

    Regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Sort by in stock product first’ is closed to new replies.