0
votes

In WooCommerce, I am trying hide a specific product in the Woocommerce product widget.

I found a solution to exclude it via category:

function exclude_widget_categories($args){
    $exclude = "11,10,8,7,9"; // IDs of excluded product categories
    $args["exclude"] = $exclude;
    return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");

But thats not what I want. I need it for a specific product with the id 2386.

How to hide a specific product in woocommerce product widget?

2

2 Answers

0
votes

You can use widget_post_args filter.

add_filter('widget_posts_args', function(){
$params['post__not_in'] = array(2386);
   return $params;
}); 
0
votes

Using a custom function hooked in woocommerce_products_widget_query_args filter hook this way:

add_filter('woocommerce_products_widget_query_args', 'exclude_product_from_widget', 10, 1 );
function exclude_product_from_widget( $query_args ){
    // HERE define your product IDs to exclude in the array
    $product_ids = array(2386);

    $query_args['post__not_in'] = $product_ids;
    return $query_args;
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested and works