• Resolved neikoloves

    (@neikoloves)


    Hello! I’d like to add a simple filter to exclude a stock status I set up called “discontinued_sku” Can you assist with this, I’m also using the WoodMart theme and have everything else working but this, small sample below, it works perfectly with the theme, but your plugin seems to override that and thus, not sure of the logic to bypass finding any discontinued_sku as we still want this product page to be found directly, just not indirectly via search or listing and not have to hand set this in the admin for all products? I did try your docs online and was not able to find the answer myself yet.

    // Exclude discontinued products from all product queries
    add_action('pre_get_posts', function($query) {
    if (!is_admin() && $query->is_main_query() && ($query->is_post_type_archive('product') || $query->is_tax() || $query->is_search())) {
    $meta_query = $query->get('meta_query') ?: [];
    $meta_query[] = ['key' => '_stock_status', 'value' => 'discontinued_sku', 'compare' => '!='];
    $query->set('meta_query', $meta_query);
    }
    });

    // Exclude discontinued products from Fibosearch results
    add_filter('fibosearch_product_query_args', function($args) {
    $meta_query = $args['meta_query'] ?? [];
    $meta_query[] = [
    'key' => '_stock_status',
    'value' => 'discontinued_sku',
    'compare' => '!='
    ];
    $args['meta_query'] = $meta_query;
    return $args;
    });

    // Exclude discontinued products from WoodMart search results
    add_filter('woocommerce_shortcode_products_query', function($args) {
    $meta_query = $args['meta_query'] ?? [];
    $meta_query[] = [
    'key' => '_stock_status',
    'value' => 'discontinued_sku',
    'compare' => '!='
    ];
    $args['meta_query'] = $meta_query;
    return $args;
    });

    Thank you …

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Kris

    (@c0nst)

    Hi @neikoloves!

    Try this way:

    add_filter( 'dgwt/wcas/search/product/args', function( $args ) {
    $meta_query = [
    [
    'key' => '_stock_status',
    'value' => 'discontinued_sku',
    'compare' => '!='
    ]
    ];

    if ( isset( $args['meta_query'] ) ) {
    $args['meta_query'][] = $meta_query;
    } else {
    $args['meta_query'] = $meta_query;
    }

    return $args;
    } );

    Best regards,
    Kris

    Thread Starter neikoloves

    (@neikoloves)

    Thank you for your response! It seems we have a bit of a conflict regarding the theme. Could you provide any additional documentation on this or a known working sample? Specifically, I’m curious if your search overwrites the integrated theme search with your search or if it operates independently somehow? Maybe we have too much logic and it conflicts when trying to combine the filters args? Thanks

    • This reply was modified 1 month, 3 weeks ago by neikoloves.
    Plugin Support Kris

    (@c0nst)

    Hi @neikoloves

    FiboSearch replaces the default WordPress search query by hooking into pre_get_posts. It edits the query parameters (like the post IDs) before the search results are retrieved, which can cause conflicts with theme search logic if the theme also modifies search queries. You can observe these modifications in action using the Query Monitor plugin, specifically by inspecting pre_get_posts the Hooks & Actions tab.

    Best regards,
    Kris

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.