Simple Exclude Question
-
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)
Viewing 3 replies - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.