/**
  * Get method returns variation meta data if set, otherwise in most cases the data from the parent.
  *
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     if (in_array($key, array_keys($this->variation_level_meta_data))) {
         $value = get_post_meta($this->variation_id, '_' . $key, true);
         if ('' === $value) {
             $value = $this->variation_level_meta_data[$key];
         }
     } elseif (in_array($key, array_keys($this->variation_inherited_meta_data))) {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : get_post_meta($this->id, '_' . $key, true);
         // Handle meta data keys which can be empty at variation level to cause inheritance
         if ('' === $value && in_array($key, array('sku', 'weight', 'length', 'width', 'height'))) {
             $value = get_post_meta($this->id, '_' . $key, true);
         }
         if ('' === $value) {
             $value = $this->variation_inherited_meta_data[$key];
         }
     } elseif ('variation_data' === $key) {
         return $this->variation_data = wc_get_product_variation_attributes($this->variation_id);
     } elseif ('variation_has_stock' === $key) {
         return $this->managing_stock();
     } else {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : parent::__get($key);
     }
     return $value;
 }
 /**
  * Get method returns variation meta data if set, otherwise in most cases the data from the parent.
  *
  * @access public
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     if (in_array($key, array_keys($this->variation_level_meta_data))) {
         $value = get_post_meta($this->variation_id, '_' . $key, true);
         if ('' === $value) {
             $value = $this->variation_level_meta_data[$key];
         }
     } elseif (in_array($key, array_keys($this->variation_inherited_meta_data))) {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : get_post_meta($this->id, '_' . $key, true);
         // Handle meta data keys which can be empty at variation level to cause inheritance
         if ('' === $value && in_array($key, array('sku', 'weight', 'length', 'width', 'height'))) {
             $value = get_post_meta($this->id, '_' . $key, true);
         }
         if ('' === $value) {
             $value = $this->variation_inherited_meta_data[$key];
         }
     } elseif ('variation_data' === $key) {
         $all_meta = get_post_meta($this->variation_id);
         // The variation data array
         $this->variation_data = array();
         // Get the variation attributes from meta
         foreach ($all_meta as $name => $value) {
             if (!strstr($name, 'attribute_')) {
                 continue;
             }
             $this->variation_data[$name] = sanitize_title($value[0]);
         }
         return $this->variation_data;
     } elseif ('variation_has_stock' === $key) {
         return $this->managing_stock();
     } else {
         $value = parent::__get($key);
     }
     return $value;
 }
 /**
  * Get method returns variation meta data if set, otherwise in most cases the data from the parent.
  *
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     if (in_array($key, array_keys($this->variation_level_meta_data))) {
         $value = get_post_meta($this->variation_id, '_' . $key, true);
         if ('' === $value) {
             $value = $this->variation_level_meta_data[$key];
         }
     } elseif (in_array($key, array_keys($this->variation_inherited_meta_data))) {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : get_post_meta($this->id, '_' . $key, true);
         // Handle meta data keys which can be empty at variation level to cause inheritance
         if ('' === $value && in_array($key, array('sku', 'weight', 'length', 'width', 'height'))) {
             $value = get_post_meta($this->id, '_' . $key, true);
         }
         if ('' === $value) {
             $value = $this->variation_inherited_meta_data[$key];
         }
     } elseif ('variation_data' === $key) {
         $all_meta = get_post_meta($this->variation_id);
         // The variation data array
         $this->variation_data = array();
         // Get the variation attributes from meta
         foreach ($all_meta as $name => $value) {
             if (0 !== strpos($name, 'attribute_')) {
                 continue;
             }
             /**
              * Pre 2.4 handling where 'slugs' were saved instead of the full text attribute.
              * Attempt to get full version of the text attribute from the parent.
              */
             if (sanitize_title($value[0]) === $value[0] && version_compare(get_post_meta($this->id, '_product_version', true), '2.4.0', '<')) {
                 $attributes = $this->parent->get_attributes();
                 foreach ($attributes as $attribute) {
                     if ($name !== 'attribute_' . sanitize_title($attribute['name'])) {
                         continue;
                     }
                     $text_attributes = wc_get_text_attributes($attribute['value']);
                     foreach ($text_attributes as $text_attribute) {
                         if (sanitize_title($text_attribute) === $value[0]) {
                             $value[0] = $text_attribute;
                         }
                     }
                 }
             }
             $this->variation_data[$name] = $value[0];
         }
         return $this->variation_data;
     } elseif ('variation_has_stock' === $key) {
         return $this->managing_stock();
     } else {
         $value = metadata_exists('post', $this->variation_id, '_' . $key) ? get_post_meta($this->variation_id, '_' . $key, true) : parent::__get($key);
     }
     return $value;
 }