/**
  * Extends the parent constructor to overwrite with variable data
  *
  * @param   int     ID of the product to load
  * @return  object
  */
 public function __construct($ID)
 {
     // Setup the product
     $parent_id = wp_get_post_parent_id($ID);
     parent::__construct($parent_id);
     // Get the meta & for each meta item overwrite with the variations ID
     $meta = get_post_custom($ID);
     $variable_stock = 0;
     foreach ($meta as $key => $array) {
         if ($array[0]) {
             $this->meta[$key] = $array;
         }
         if ($key == 'sku') {
             if (empty($array[0])) {
                 $tempsku = $ID;
             }
         }
         if ($key == 'stock') {
             // if no value then parent stock value is used for variation stock tracking
             // otherwise the variation stock even if '0' as that is a value, is used
             if ($array[0] == '') {
                 $variable_stock = '-9999999';
             } else {
                 $variable_stock = $array[0];
             }
         }
     }
     // Merge with the variation data
     $this->variation_id = $ID;
     if (isset($this->meta['variation_data'][0])) {
         $this->variation_data = maybe_unserialize($this->meta['variation_data'][0]);
     }
     $sale_from = $this->sale_price_dates_from;
     $sale_to = $this->sale_price_dates_to;
     parent::__construct($ID);
     // Restore the parent ID
     $this->ID = $parent_id;
     $this->id = $parent_id;
     if (!empty($tempsku)) {
         $this->sku = $tempsku;
     }
     $this->sale_price_dates_from = $sale_from;
     $this->sale_price_dates_to = $sale_to;
     // signal parent stock tracking or variation stock tracking
     $this->stock = $variable_stock == '-9999999' ? $variable_stock : $this->stock;
     return $this;
 }