Try replacing 'operator' => 'AND'
with 'relation'=>'AND'
Updated Code Snippet:
$current_color = get_queried_object_id();
$query = new WP_Query( array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND'
array(
'taxonomy' => 'pa_color',
'field' => 'term_id',
'terms' => $current_color,
),
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $cats
)
)
) );
Reference : https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters ( Multiple Taxonomy Handling )
Edit 1: You can edit above query to return only ids
( ‘fields’ => ‘ids’ ) and use get_terms
for those IDs to get the list of categories
get_terms( array(
'taxonomy' => 'product_cat',
'object_ids' => $posts_matching_criteria
);
Ref 1 : https://developer.wordpress.org/reference/functions/get_terms/
Ref 2 : https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#user-contributed-notes