'Exclude custom taxonomy from product query

In a woocommerce installation I added custom taxonomies for products. One of them is season with a term 'sale'.

I want to exclude these sale items from the shop page. So I used below function, but it doesn't seem to work. Is this function actually working for a custom taxonomy?

Source code: https://woocommerce.com/document/exclude-a-category-from-the-shop-page/

add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );  
function custom_pre_get_posts_query( $q ) {
    global $woocommerce;
        $tax_query = (array) $q->get( 'tax_query' );
        $tax_query[] = array(
               'taxonomy' => 'season', // taxonomy
               'field' => 'slug',
               'terms' => array( 'sale' ), //slug taxonomies
               'operator' => 'NOT IN'
        );
        $q->set( 'tax_query', $tax_query );
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source