/**
  * Save ML product data
  *
  * @action( hook: "woocommerce_process_product_meta_variable" )
  * @action( hook: "woocommerce_process_product_meta_simple" )
  */
 public function save_product_metaboxes_data($post_id)
 {
     $ml_product = new ML_Product($post_id);
     $ml_product->video_id = $_POST['ml_video_id'];
     if (!$ml_product->is_published()) {
         // Fields for a new product
         $ml_product->category_id = $_POST['ml_category_id'];
         $ml_product->listing_type_id = $_POST['ml_listing_type_id'];
         if (!empty($_POST['ml_official_store_id'])) {
             $ml_product->official_store_id = $_POST['ml_official_store_id'];
         }
     }
     if ($ml_product->can_update_special_fields()) {
         // Fields that can only be updated when the product has no sales
         $ml_product->title = sanitize_text_field($_POST['ml_title']);
         //$ml_product->buying_mode  = $_POST['ml_buying_mode'];
         //$ml_product->condition    = $_POST['ml_condition'];
         $ml_product->warranty = $_POST['ml_warranty'];
         if (isset($_POST['ml_shipping_mode']) && $_POST['ml_shipping_mode'] == 'custom') {
             // Custom Shipping
             $costs = array();
             for ($i = 0; $i < 10; $i++) {
                 if (empty($_POST['ml_shipment_data'][$i]['description']) || empty($_POST['ml_shipment_data'][$i]['cost'])) {
                     continue;
                 }
                 $costs[] = array('description' => sanitize_text_field($_POST['ml_shipment_data'][$i]['description']), 'cost' => floatval($_POST['ml_shipment_data'][$i]['cost']));
             }
             $ml_product->shipping_mode = 'custom';
             $ml_product->shipment_costs = $costs;
             $ml_product->shipment_local_pickup = $_POST['ml_shipment_local_pickup'] == 'yes';
             if (isset($_POST['ml_shipment_free_shipping'])) {
                 $ml_product->shipment_free_shipping = $_POST['ml_shipment_free_shipping'] == 'yes';
             } else {
                 $ml_product->shipment_free_shipping = false;
             }
         }
     }
     if (!$ml_product->is_published() || !$ml_product->is_variable()) {
         $ml_product->price = sanitize_text_field($_POST['ml_price']);
     }
     if ($ml_product->is_variable()) {
         // Set variations
         $number_of_variations = count($_POST['ml_variations']['child']);
         $attributes = array_diff(array_keys($_POST['ml_variations']), array('child', 'price'));
         for ($position = 0; $position < $number_of_variations; $position++) {
             $child_product = new ML_Product(intval($_POST['ml_variations']['child'][$position]));
             if (!$child_product->is_published()) {
                 $attribute_combinations = array();
                 foreach ($attributes as $attribute) {
                     if (!empty($_POST['ml_variations'][$attribute][$position])) {
                         $attribute_combinations[] = array('id' => strval($attribute), 'value_id' => strval($_POST['ml_variations'][$attribute][$position]));
                     }
                 }
                 $child_product->attribute_combinations = $attribute_combinations;
             }
             $child_product->price = sanitize_text_field($_POST['ml_variations']['price'][$position]);
         }
     }
     if ($ml_product->is_published() && (ML()->ml_auto_update == 'yes' || isset($_POST['ml_publish']) && $_POST['ml_publish'] == 'yes')) {
         // Verify aditional changes and update
         try {
             // Update the product
             $new_ml_product = $ml_product->update();
             if ($_POST['ml_listing_type_id'] != $new_ml_product->listing_type_id) {
                 $ml_product->update_listing_type($_POST['ml_listing_type_id']);
             }
             if (!empty($ml_product->get_wc_product()->get_post_data()->post_content)) {
                 $ml_product->update_description();
             }
             // Enqueue a message for the user
             ML()->add_notice(sprintf('%s: <a href="%s" target="_blank">%s</a>', __('The product has been updated successfully on MercadoLivre', ML()->textdomain), $new_ml_product->permalink, $new_ml_product->permalink), 'success');
         } catch (ML_Exception $e) {
             ML()->add_notice(sprintf('%s: %s', __('The product could not be updated on MercadoLivre', ML()->textdomain), $e->getMessage()), 'error');
         }
     } else {
         if (!$ml_product->is_published() && (ML()->ml_auto_export == 'yes' || isset($_POST['ml_publish']) && $_POST['ml_publish'] == 'yes')) {
             // Post
             try {
                 // Post the product
                 $new_ml_product = $ml_product->post();
                 // Enqueue a message for the user
                 ML()->add_notice(sprintf('%s: <a href="%s" target="_blank">%s</a>', __('The product was successfully published on MercadoLivre', ML()->textdomain), $new_ml_product->permalink, $new_ml_product->permalink), 'success');
             } catch (ML_Exception $e) {
                 ML()->add_notice(sprintf('%s: %s', __('The product could not be posted on MercadoLivre', ML()->textdomain), $e->getMessage()), 'error');
             }
         }
     }
 }