• Resolved koivunahka

    (@koivunahka)


    I manually hid the products with this code:

    add_action ( ‘pre_get_posts’, ‘hide_out_of_stock_in_search’) ;
    function hide_out_of_stock_in_search ($query){
    if($query->is_search() && $query->is_main_query()){
    $query->set (‘meta_key’,’_stock_status’);
    $query->set (‘meta_value’,’instock’);
    }
    }

    This code also “breaks” the “order search” in adminpage. I can’t find orders by name or order number. How could this be fixed?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter koivunahka

    (@koivunahka)

    Solvet:

    add_action ( ‘pre_get_posts’, ‘hide_out_of_stock_in_search’) ;
    function hide_out_of_stock_in_search ($query){
    if ( is_admin() ) {
    return;
    }
    if( $query->is_search() && $query->is_main_query() && ‘product’ === $query->get( ‘post_type’ ) ){
    $query->set( ‘meta_key’, ‘_stock_status’ );
    $query->set( ‘meta_value’, ‘instock’ );
    }
    }

    Hello,

    Glad to hear that you figured this out.

    I’m going to mark this as resolved – if you have any other questions, feel free to create a new thread.

    Kind regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Order search not working’ is closed to new replies.