How to hide a product from certain categories on the seller store in dokan

I tried this code in functions.php but it didn’t do anything I still see the product of category id 52. Please help me

function dokan_dashboard_sort( $args ) {

  $args['category__not_in'] = array( 52 );

  return $args;
}  

add_filter( 'dokan_dashboard_query', 'dokan_dashboard_sort');

To exclude a product that belongs to a certain category from the query on the seller store, you could use the combination of:

  • pre_get_posts action hook, to manipulate the query.

And

  • dokan_is_store_page() function, to check whether you're manipulating the query on the correct page or not.

I've also used a low priority (i.e 999) to make sure there won't be a conflict between other queries, from the theme and/or other third party plugins, and this query.

So use the following code in the functions.php file:

add_action('pre_get_posts', 'dokan_excluding_certain_cat_from_seller_store', 999); 

function dokan_excluding_certain_cat_from_seller_store($query)
{
    if (dokan_is_store_page()) 
    {
        $tax_query = array(
            array(
                'taxonomy' => 'product_cat',
                'field'    => 'id',
                'terms'    => array(52),
                'operator' => 'NOT IN',
            )
        );
        $query->set('tax_query', $tax_query);
    }
}

This answer has been tested on Dokan 3.3.5 and Woo 5.7 and works.