0

I am trying to get the value of a selected product color (attribute slug) in Woocommerce. This works fine with my code for the 'pa_size' and 'pa_mountcolor' attributes but my 'pa_color' attributes has no values. I think that's because in Woocommerce I set this variation attribute as 'any option', Any idea how to get the value of 'pa_color' with this option selected? (I don't want too many variations in Woocommerce because the product images and prices are the same).

            foreach($variation_attributes as $attribute_taxonomy => $term_slug ){

                // Get product attribute name or taxonomy
                $taxonomy = str_replace('attribute_', '', $attribute_taxonomy );
                // The label name from the product attribute
                $attribute_name = wc_attribute_label( $taxonomy, $product );

                // If slug of afmetingen, get the printapi productId 
                if ($taxonomy == "pa_color"){
                    echo $term_slug;
                    $attr_frame_color = $term_slug;
                } else if ($taxonomy == "pa_photo_frame"){
                    //$printapi_hanging_system = $term_slug;
                }
            }

enter image description here

aynber
  • 22,380
  • 8
  • 50
  • 63
Edwin
  • 67
  • 1
  • 5

1 Answers1

0

This is the solution:

        foreach ($item->get_meta_data() as $metaData) {
            $attribute = $metaData->get_data();

            // attribute value
            $value = $attribute['value'];

            // attribute slug
            $slug = $attribute['key'];

            if($slug == 'pa_color'){
                $attr_frame_color = $value;
            }
        }
Edwin
  • 67
  • 1
  • 5