{ if (isset($_POST['_unit'])) { update_post_meta($post_id, '_unit', sanitize_text_field($_POST['_unit'])); } if (isset($_POST['_unit_base'])) { update_post_meta($post_id, '_unit_base', $_POST['_unit_base'] === '' ? '' : wc_format_decimal($_POST['_unit_base'])); } if (isset($_POST['_unit_price_regular'])) { update_post_meta($post_id, '_unit_price_regular', $_POST['_unit_price_regular'] === '' ? '' : wc_format_decimal($_POST['_unit_price_regular'])); update_post_meta($post_id, '_unit_price', $_POST['_unit_price_regular'] === '' ? '' : wc_format_decimal($_POST['_unit_price_regular'])); } if (isset($_POST['_unit_price_sale'])) { update_post_meta($post_id, '_unit_price_sale', ''); // Update Sale Price only if is on sale (Cron?!) if (get_post_meta($post_id, '_price', true) != $_POST['_regular_price'] && $_POST['_unit_price_sale'] !== '') { update_post_meta($post_id, '_unit_price_sale', $_POST['_unit_price_sale'] === '' ? '' : wc_format_decimal($_POST['_unit_price_sale'])); update_post_meta($post_id, '_unit_price', $_POST['_unit_price_sale'] === '' ? '' : wc_format_decimal($_POST['_unit_price_sale'])); } } if (isset($_POST['_mini_desc'])) { update_post_meta($post_id, '_mini_desc', esc_html($_POST['_mini_desc'])); } if (isset($_POST['delivery_time']) && !is_numeric($_POST['delivery_time'])) { wp_set_post_terms($post_id, sanitize_text_field($_POST['delivery_time']), 'product_delivery_time'); } else { wp_set_object_terms($post_id, absint($_POST['delivery_time']), 'product_delivery_time'); } } } WC_Germanized_Meta_Box_Product_Data::init();
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')); } }