• Resolved imloic

    (@imloic)


    Hello,

    I know I can show stock status on the search bar, but, I would like to show stock status only for “out of stock” products. There is a snippet for me please?

    Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    Yes, please use following code snippet to achieve this:

    add_filter('aws_search_pre_filter_single_product', 'my_aws_search_pre_filter_single_product', 10, 3);
    function my_aws_search_pre_filter_single_product( $new_result, $post_id, $product ) {
        if ( $new_result['stock_status']['status'] ) {
            $new_result['stock_status'] = '';
        }
        return $new_result;
    }

    You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.

    Also, after adding this code you will need to go to the plugin settings page and click the ‘Clear cache’ button.

    Regards

    Thread Starter imloic

    (@imloic)

    Hello, file (function.php)was edited successfully but this doesn’t work. WordPress says: “There was a critical error on this site”.I can’t search for a product.

    • This reply was modified 2 years, 1 month ago by imloic.
    Plugin Author ILLID

    (@mihail-barinov)

    Can you please show me a screenshot of how this code looks inside your function.php file?

    Thread Starter imloic

    (@imloic)

    Fucntion.php. Correctly edited when I press UPDATE.

    https://ibb.co/FmgrXVd

    Plugin Author ILLID

    (@mihail-barinov)

    So it is still throw an error when you are trying to search something?

    Thread Starter imloic

    (@imloic)

    The search wheel doesn’t work and when I hit enter I got this message :

    https://kinsta.com/wp-content/uploads/2021/05/wordpress-critical-error.png

    Plugin Author ILLID

    (@mihail-barinov)

    Ok, one more thing. Did you enable stock status showing in the plugin settings page?

    Thread Starter imloic

    (@imloic)

    You’re right! It was on “HIDE”. It’s OK but it’s possible to show “Discontinued product” instead of “Out of Stock”?

    Thanks

    Plugin Author ILLID

    (@mihail-barinov)

    In this case please modify your code snippet and use this version instead:

    add_filter('aws_search_pre_filter_single_product', 'my_aws_search_pre_filter_single_product', 10, 3);
    function my_aws_search_pre_filter_single_product( $new_result, $post_id, $product ) {
        if ( $new_result['stock_status']['status'] ) {
            $new_result['stock_status'] = '';
        } else {
            $new_result['stock_status']['text'] = 'Discontinued product';
        }
        return $new_result;
    }
    Thread Starter imloic

    (@imloic)

    Perfect! I just adapted the code for WPML. Work well. I hope I don’t make errors.

    add_filter('aws_search_pre_filter_single_product', 'my_aws_search_pre_filter_single_product', 10, 3);
    
    function my_aws_search_pre_filter_single_product( $new_result, $post_id, $product ) {
    
    ? ? if ( $new_result['stock_status']['status'] ) {
    
    ? ? ? ? $new_result['stock_status'] = '';
    
    ? ? } else {
    
    if(ICL_LANGUAGE_CODE == 'en'){
    
    ? ? ? ? $new_result['stock_status']['text'] = 'Discontinued product';
    
    }
    
    if(ICL_LANGUAGE_CODE == 'fr'){
    
    ? ? ? ? $new_result['stock_status']['text'] = 'Produit arrêté';
    
    }
    
    }
    
    ? ? return $new_result;
    
    }
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘show out of stock custom fields only’ is closed to new replies.