How to display two different custom taxonomy terms on a WooCommerce single product page

The WordPress documentation shows that an array is an acceptable argument for the taxonomy in get_the_terms (https://developer.wordpress.org/reference/functions/get_the_terms/). An array works if you are trying to get multiple taxonomies. It even works if you are trying to get just one taxonomy. But getting two single taxonomy arrays sequentially is what breaks this code.

In the originally posted code, replacing this:

$size_terms = get_the_terms( $post->ID , array( 'sizes') );

with this instead:

$size_terms = get_the_terms( $post->ID , 'sizes' );

And also replacing this:

$color_terms = get_the_terms( $post->id , array( 'colors') );

with this instead:

$color_terms = get_the_terms( $post->id , 'colors' );

solves the problem.

Another alternative that works is to retrieve both sets of taxonomy terms at once, and then tease apart the WP_Term Object to find exactly what you want. This is probably the better solution in most cases.

function display_single_product_taxonomy_terms() {
    global $post;
    
    $tax_terms = get_the_terms( $post->ID , array( 'sizes','colors') );
    // create the markup variables
    $color_markup = '';
    $size_markup = '';
    // init counters
    $color_counter = 0;
    $size_counter = 0;
    
    foreach ( $tax_terms as $tax_term ) {
        if( $tax_term->taxonomy == 'colors' ) {
            // this is a colors term; increment color counter
            $color_counter++;
            // add to color markup
            $color_markup .= ($color_counter > 1)? "; " : "";
            $color_markup .= '<a href="/shades/color/' . $tax_term->slug . '">' . str_replace(", and,"," and",str_replace("-", ", ", $tax_term->slug)) . '</a>';
        } else {
            // this is a sizes term; increment size counter
            $size_counter++;
            // add to size markup
            $size_markup .= ($size_counter > 1)? "; " : "";
            $size_markup .= '<a href="/shades/size/' . $tax_term->slug . '">' . str_replace("-", " ", $tax_term->slug) . '</a>';
        }
    };
    
    echo '<div class="single-product-taxonomy-terms">' . PHP_EOL;
    if ( $size_counter > 0 ) {
        echo '<p>'. __("Similar size shades: ","bright-side") . $size_markup . '</p>' . PHP_EOL;
    };
    if ( $color_counter > 0 ) {
        echo '<p>' . __("Similar color shades: ","bright-side") . $color_markup . '</p>' . PHP_EOL;
    };
    echo '</div>' . PHP_EOL;
};
add_action( 'woocommerce_single_product_summary', 'display_single_product_taxonomy_terms', 101, 0 );