In fact, product attributes are actually terms in custom taxonomy, so you just need to get the conditions in that particular taxonomy. All attribute taxonomies are preceded by "pa_". Thus, the size attribute will be the pa_size taxonomy. And the change identifier is the message identifier for the variation.
But depending on how you want to display it, WooCommerce has a built-in function to display all change attributes:
The following is a list of definitions for all attribute attributes.
echo wc_get_formatted_variation( $product->get_variation_attributes() );
And when passing the second parameter true
, a flat list will be displayed:
echo wc_get_formatted_variation( $product->get_variation_attributes(), true );
source share