public static function save($variation_id, $i) { $data = array('_unit' => '', '_unit_base' => '', '_unit_product' => '', '_unit_price_auto' => '', '_unit_price_regular' => '', '_unit_price_sale' => '', '_mini_desc' => '', 'delivery_time' => ''); foreach ($data as $k => $v) { $data_k = 'variable' . (substr($k, 0, 1) === '_' ? '' : '_') . $k; $data[$k] = isset($_POST[$data_k][$i]) ? $_POST[$data_k][$i] : null; } $product = wc_get_product($variation_id); $data['product-type'] = isset($product->parent) ? $product->parent->product_type : $product->type; $data['_sale_price_dates_from'] = $_POST['variable_sale_price_dates_from'][$i]; $data['_sale_price_dates_to'] = $_POST['variable_sale_price_dates_to'][$i]; $data['_sale_price'] = $_POST['variable_sale_price'][$i]; WC_Germanized_Meta_Box_Product_Data::save_product_data($variation_id, $data, true); }
private function import_single_product_data($product) { $save = array('product-type' => $product->get_type(), '_unit_price_sale' => '', '_unit_price_regular' => ''); // Price per unit if (get_post_meta($product->id, '_regular_price_per_unit', true)) { $regular = get_post_meta($product->id, '_regular_price_per_unit', true); $base = get_post_meta($product->id, '_unit_regular_price_per_unit_mult', true); $sale = get_post_meta($product->id, '_sale_price_per_unit', true); $unit = get_post_meta($product->id, '_unit_regular_price_per_unit', true); if ($unit) { $unit_term = get_term_by('slug', $unit, $this->taxonomies['product_unit']); if ($unit_term && !is_wp_error($unit_term)) { $gzd_term = false; if (!($gzd_term = get_term_by('slug', $unit, 'product_unit'))) { $gzd_term = wp_insert_term($unit_term->name, 'product_unit', array('description' => $unit_term->description)); } if ($gzd_term && !is_wp_error($gzd_term)) { $save['_unit'] = $gzd_term->slug; $save['_unit_base'] = $base; $save['_unit_price_regular'] = $regular; $save['_unit_price_sale'] = $sale; $save['_sale_price'] = $product->get_sale_price(); $save['_sale_price_dates_from'] = get_post_meta($product->id, '_sale_price_dates_from', true) ? get_post_meta($product->id, '_sale_price_dates_from', true) : ''; $save['_sale_price_dates_to'] = get_post_meta($product->id, '_sale_price_dates_to', true) ? get_post_meta($product->id, '_sale_price_dates_to', true) : ''; } } } } // Delivery time if ($delivery_time = get_post_meta($product->id, '_lieferzeit', true)) { $term = get_term_by('id', $delivery_time, $this->taxonomies['product_delivery_time']); if ($term && !is_wp_error($term)) { $save['delivery_time'] = $term->name; } } // Free shipping if ('on' === get_post_meta($product->id, '_suppress_shipping_notice', true) && !$product->is_type('variation')) { $save['_free_shipping'] = 'yes'; } // Save if (sizeof($save) > 3) { WC_Germanized_Meta_Box_Product_Data::save_product_data($product->id, $save, $product->is_type('variation')); } }