ARTICLE AD BOX
The issue is how WooCommerce handles "Any" variation attributes. When an attribute on a variation is set to "Any", WooCommerce doesn't store a specific value for that attribute on the variation itself — it just inherits from the parent product. That's why wc_get_product_variation_attributes() returns an empty string for attribute_pa_material.
Your approach of fetching from the parent is correct, but get_meta('pa_material') is the wrong key. Product attributes are stored as taxonomy terms, not post meta. You need to pull them using get_the_terms() or wc_get_product()->get_attribute().
Here's what works:
$parent_id = $product->get_parent_id(); $parent = wc_get_product( $parent_id ); // get all terms assigned to this attribute on the parent $terms = get_the_terms( $parent_id, 'pa_material' ); if ( $terms && ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { error_log( $term->name ); // e.g. "Cotton", "Polyester" } }Or if you just want a comma-separated string (same as shown on the product page):
$material = $parent->get_attribute( 'pa_material' ); error_log( $material );get_attribute() handles the term lookup internally and returns the label(s), so it's usually the cleanest option for display purposes.
One thing worth noting — if the product is a simple product (not variable), get_parent_id() returns 0, so make sure you're only running this logic when $product->is_type('variation') is true.
