Try using the following filter-hook, it’ll remove the main variable product and display it’s variations instead:
add_filter( 'wc_zap_mirror_wp_query', function( $args ) {
// Include product variations
$args['post_type'] = [ 'product', 'product_variation' ];
// Exclude the main variable product
$args['tax_query'][] = [
'taxonomy' => 'product_type',
'field' => 'name',
'terms' => 'variable',
'include_children' => false,
'operator' => 'NOT IN'
];
// Quick fix: variations are not assigned to product categories
add_filter( 'posts_join', function( $join, $query ) {
global $wpdb;
$table = $query->tax_query->primary_table;
$column = $query->tax_query->primary_id_column;
$search = "{$table}.{$column} = {$wpdb->term_relationships}.object_id";
$replace = "{$search} OR {$table}.post_parent = {$wpdb->term_relationships}.object_id";
return str_replace($search, $replace, $join);
}, 10, 2 );
return $args;
} );
Just paste in your theme’s functions.php file.