本文整理汇总了PHP中wc_update_product_stock函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_update_product_stock函数的具体用法?PHP wc_update_product_stock怎么用?PHP wc_update_product_stock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_update_product_stock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wc_reduce_stock_levels
/**
* Reduce stock levels for items within an order.
* @since 2.7.0
* @param int $order_id
*/
function wc_reduce_stock_levels($order_id)
{
$order = wc_get_order($order_id);
if ('yes' === get_option('woocommerce_manage_stock') && $order && apply_filters('woocommerce_can_reduce_order_stock', true, $order) && sizeof($order->get_items()) > 0) {
foreach ($order->get_items() as $item) {
if ($item->is_type('line_item') && ($product = $item->get_product()) && $product->managing_stock()) {
$qty = apply_filters('woocommerce_order_item_quantity', $item->get_quantity(), $order, $item);
$item_name = $product->get_formatted_name();
$new_stock = wc_update_product_stock($product, $qty, 'decrease');
if (!is_wp_error($new_stock)) {
/* translators: 1: item name 2: old stock quantity 3: new stock quantity */
$order->add_order_note(sprintf(__('%1$s stock reduced from %2$s to %3$s.', 'woocommerce'), $item_name, $new_stock + $qty, $new_stock));
if ('' !== get_option('woocommerce_notify_no_stock_amount') && $new_stock <= get_option('woocommerce_notify_no_stock_amount')) {
do_action('woocommerce_no_stock', $product);
} elseif ('' !== get_option('woocommerce_notify_low_stock_amount') && $new_stock <= get_option('woocommerce_notify_low_stock_amount')) {
do_action('woocommerce_low_stock', $product);
}
if ($new_stock < 0) {
do_action('woocommerce_product_on_backorder', array('product' => $product, 'order_id' => $order_id, 'quantity' => $qty_ordered));
}
}
}
}
do_action('woocommerce_reduce_order_stock', $order);
}
}
示例2: test_wc_update_product_stock
/**
* Test wc_update_product_stock()
*
* @since 2.3
*/
public function test_wc_update_product_stock()
{
// Create product
$product = \WC_Helper_Product::create_simple_product();
update_post_meta($product->id, '_manage_stock', 'yes');
wc_update_product_stock($product->id, 5);
$this->assertEquals(5, $product->stock);
// Delete Product
\WC_Helper_Product::delete_product($product->id);
}
示例3: save_variations_data
//.........这里部分代码省略.........
}
update_post_meta($variation_id, '_thumbnail_id', $attachment_id);
}
} else {
delete_post_meta($variation_id, '_thumbnail_id');
}
}
// Virtual variation.
if (isset($variation['virtual'])) {
$is_virtual = true === $variation['virtual'] ? 'yes' : 'no';
update_post_meta($variation_id, '_virtual', $is_virtual);
}
// Downloadable variation.
if (isset($variation['downloadable'])) {
$is_downloadable = true === $variation['downloadable'] ? 'yes' : 'no';
update_post_meta($variation_id, '_downloadable', $is_downloadable);
} else {
$is_downloadable = get_post_meta($variation_id, '_downloadable', true);
}
// Shipping data.
$this->save_product_shipping_data($variation_id, $variation);
// Stock handling.
if (isset($variation['manage_stock'])) {
$manage_stock = true === $variation['manage_stock'] ? 'yes' : 'no';
} else {
$manage_stock = get_post_meta($variation_id, '_manage_stock', true);
}
update_post_meta($variation_id, '_manage_stock', '' === $manage_stock ? 'no' : $manage_stock);
if (isset($variation['in_stock'])) {
$stock_status = true === $variation['in_stock'] ? 'instock' : 'outofstock';
} else {
$stock_status = get_post_meta($variation_id, '_stock_status', true);
}
wc_update_product_stock_status($variation_id, '' === $stock_status ? 'instock' : $stock_status);
if ('yes' === $manage_stock) {
$backorders = get_post_meta($variation_id, '_backorders', true);
if (isset($variation['backorders'])) {
$backorders = $variation['backorders'];
}
update_post_meta($variation_id, '_backorders', '' === $backorders ? 'no' : $backorders);
if (isset($variation['stock_quantity'])) {
wc_update_product_stock($variation_id, wc_stock_amount($variation['stock_quantity']));
} elseif (isset($request['inventory_delta'])) {
$stock_quantity = wc_stock_amount(get_post_meta($variation_id, '_stock', true));
$stock_quantity += wc_stock_amount($request['inventory_delta']);
wc_update_product_stock($variation_id, wc_stock_amount($stock_quantity));
}
} else {
delete_post_meta($variation_id, '_backorders');
delete_post_meta($variation_id, '_stock');
}
// Regular Price.
if (isset($variation['regular_price'])) {
$regular_price = '' === $variation['regular_price'] ? '' : $variation['regular_price'];
} else {
$regular_price = get_post_meta($variation_id, '_regular_price', true);
}
// Sale Price.
if (isset($variation['sale_price'])) {
$sale_price = '' === $variation['sale_price'] ? '' : $variation['sale_price'];
} else {
$sale_price = get_post_meta($variation_id, '_sale_price', true);
}
if (isset($variation['date_on_sale_from'])) {
$date_from = $variation['date_on_sale_from'];
} else {
示例4: wc1c_replace_offer_post_meta
function wc1c_replace_offer_post_meta($is_full, $post_id, $offer, $attributes = array())
{
$price = isset($offer['Цена']['ЦенаЗаЕдиницу']) ? wc1c_parse_decimal($offer['Цена']['ЦенаЗаЕдиницу']) : null;
if (!is_null($price)) {
$coefficient = isset($offer['Цена']['Коэффициент']) ? wc1c_parse_decimal($offer['Цена']['Коэффициент']) : null;
if (!is_null($coefficient)) {
$price *= $coefficient;
}
}
$post_meta = array();
if (!is_null($price)) {
$post_meta['_regular_price'] = $price;
$post_meta['_manage_stock'] = 'yes';
}
if ($attributes) {
foreach ($attributes as $attribute_name => $attribute_value) {
$meta_key = 'attribute_' . sanitize_title($attribute_name);
$post_meta[$meta_key] = $attribute_value;
}
$current_post_meta = get_post_meta($post_id);
foreach ($current_post_meta as $meta_key => $meta_value) {
$current_post_meta[$meta_key] = $meta_value[0];
}
foreach ($current_post_meta as $meta_key => $meta_value) {
if (strpos($meta_key, 'attribute_') !== 0 || array_key_exists($meta_key, $post_meta)) {
continue;
}
delete_post_meta($post_id, $meta_key);
}
}
if (!is_null($price)) {
$sale_price = @$current_post_meta['_sale_price'];
$sale_price_from = @$current_post_meta['_sale_price_dates_from'];
$sale_price_to = @$current_post_meta['_sale_price_dates_to'];
if (empty($current_post_meta['_sale_price'])) {
$post_meta['_price'] = $price;
} else {
if (empty($sale_price_from) && empty($sale_price_to)) {
$post_meta['_price'] = $current_post_meta['_sale_price'];
} else {
$now = strtotime('now', current_time('timestamp'));
if (!empty($sale_price_from) && strtotime($sale_price_from) < $now) {
$post_meta['_price'] = $current_post_meta['_sale_price'];
}
if (!empty($sale_price_to) && strtotime($sale_price_to) < $now) {
$post_meta['_price'] = $price;
$post_meta['_sale_price_dates_from'] = '';
$post_meta['_sale_price_dates_to'] = '';
}
}
}
}
foreach ($post_meta as $meta_key => $meta_value) {
$current_meta_value = @$current_post_meta[$meta_key];
if ($meta_value !== '' && $current_meta_value == $meta_value) {
continue;
}
if ($meta_value === '' && $current_meta_value === $meta_value) {
continue;
}
update_post_meta($post_id, $meta_key, $meta_value);
}
$quantity = isset($offer['Количество']) ? $offer['Количество'] : @$offer['КоличествоНаСкладе'];
if (!is_null($quantity)) {
$quantity = wc1c_parse_decimal($quantity);
wc_update_product_stock($post_id, $quantity);
$stock_status = $quantity > 0 ? 'instock' : 'outofstock';
@wc_update_product_stock_status($post_id, $stock_status);
}
do_action('wc1c_post_offer_meta', $post_id, $offer, $is_full);
}
示例5: column_save
//.........这里部分代码省略.........
if (!$product->is_virtual()) {
update_post_meta($post->ID, '_weight', $value === '' ? '' : wc_format_decimal($value));
}
break;
case 'column-wc-dimensions':
if (is_array($value) && isset($value['length']) && isset($value['width']) && isset($value['height'])) {
$product = get_product($post->ID);
if (!$product->is_virtual()) {
update_post_meta($post->ID, '_length', $value === '' ? '' : wc_format_decimal($value['length']));
update_post_meta($post->ID, '_width', $value === '' ? '' : wc_format_decimal($value['width']));
update_post_meta($post->ID, '_height', $value === '' ? '' : wc_format_decimal($value['height']));
}
}
break;
case 'sku':
$product = get_product($post->ID);
$current_sku = get_post_meta($post->ID, '_sku', true);
$new_sku = wc_clean($value);
if (empty($new_sku)) {
$new_sku = '';
}
if ($new_sku != $current_sku) {
$existing_id = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\tSELECT {$wpdb->posts}.ID\n\t\t\t\t\t FROM {$wpdb->posts}\n\t\t\t\t\t LEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\n\t\t\t\t\t WHERE {$wpdb->posts}.post_type = 'product'\n\t\t\t\t\t AND {$wpdb->posts}.post_status = 'publish'\n\t\t\t\t\t AND {$wpdb->postmeta}.meta_key = '_sku' AND {$wpdb->postmeta}.meta_value = %s\n\t\t\t\t\t", $new_sku));
if ($existing_id) {
return new WP_Error('cacie_error_sku_exists', __('The SKU must be unique.', 'cpac'));
}
update_post_meta($post->ID, '_sku', $new_sku);
}
break;
case 'is_in_stock':
if (get_option('woocommerce_manage_stock') == 'yes') {
if ($value['manage_stock'] == 'yes') {
update_post_meta($post->ID, '_manage_stock', 'yes');
wc_update_product_stock_status($post->ID, wc_clean($value['stock_status']));
wc_update_product_stock($post->ID, intval($value['stock']));
} else {
// Don't manage stock
update_post_meta($post->ID, '_manage_stock', 'no');
update_post_meta($post->ID, '_stock', '');
wc_update_product_stock_status($post->ID, wc_clean($value['stock_status']));
}
} else {
wc_update_product_stock_status($post->ID, wc_clean($value['stock_status']));
}
break;
case 'column-wc-stock-status':
wc_update_product_stock_status($post->ID, wc_clean($value));
break;
case 'column-wc-free_shipping':
update_post_meta($id, 'free_shipping', $value == 'yes' ? 'yes' : 'no');
break;
case 'column-wc-shipping_class':
$this->set_post_terms($id, $value, 'product_shipping_class');
break;
case 'column-wc-apply_before_tax':
update_post_meta($id, 'apply_before_tax', $value == 'yes' ? 'yes' : 'no');
break;
case 'column-wc-backorders_allowed':
if (in_array($value, array('no', 'yes', 'notify'))) {
update_post_meta($post->ID, '_backorders', $value);
}
break;
case 'column-wc-upsells':
$upsell_ids = array();
if (is_array($value)) {
foreach ($value as $upsell_id) {
示例6: bulk_edit_save
/**
* Bulk edit
* @param integer $post_id
* @param WC_Product $product
*/
public function bulk_edit_save($post_id, $product)
{
$old_regular_price = $product->regular_price;
$old_sale_price = $product->sale_price;
// Save fields
if (!empty($_REQUEST['change_weight']) && isset($_REQUEST['_weight'])) {
update_post_meta($post_id, '_weight', wc_clean(stripslashes($_REQUEST['_weight'])));
}
if (!empty($_REQUEST['change_dimensions'])) {
if (isset($_REQUEST['_length'])) {
update_post_meta($post_id, '_length', wc_clean(stripslashes($_REQUEST['_length'])));
}
if (isset($_REQUEST['_width'])) {
update_post_meta($post_id, '_width', wc_clean(stripslashes($_REQUEST['_width'])));
}
if (isset($_REQUEST['_height'])) {
update_post_meta($post_id, '_height', wc_clean(stripslashes($_REQUEST['_height'])));
}
}
if (!empty($_REQUEST['_tax_status'])) {
update_post_meta($post_id, '_tax_status', wc_clean($_REQUEST['_tax_status']));
}
if (!empty($_REQUEST['_tax_class'])) {
$tax_class = wc_clean($_REQUEST['_tax_class']);
if ('standard' == $tax_class) {
$tax_class = '';
}
update_post_meta($post_id, '_tax_class', $tax_class);
}
if (!empty($_REQUEST['_stock_status'])) {
$stock_status = wc_clean($_REQUEST['_stock_status']);
if ($product->is_type('variable')) {
foreach ($product->get_children() as $child_id) {
if ('yes' !== get_post_meta($child_id, '_manage_stock', true)) {
wc_update_product_stock_status($child_id, $stock_status);
}
}
WC_Product_Variable::sync_stock_status($post_id);
} else {
wc_update_product_stock_status($post_id, $stock_status);
}
}
if (!empty($_REQUEST['_shipping_class'])) {
$shipping_class = '_no_shipping_class' == $_REQUEST['_shipping_class'] ? '' : wc_clean($_REQUEST['_shipping_class']);
wp_set_object_terms($post_id, $shipping_class, 'product_shipping_class');
}
if (!empty($_REQUEST['_visibility'])) {
if (update_post_meta($post_id, '_visibility', wc_clean($_REQUEST['_visibility']))) {
do_action('woocommerce_product_set_visibility', $post_id, wc_clean($_REQUEST['_visibility']));
}
}
if (!empty($_REQUEST['_featured'])) {
if (update_post_meta($post_id, '_featured', stripslashes($_REQUEST['_featured']))) {
delete_transient('wc_featured_products');
}
}
// Sold Individually
if (!empty($_REQUEST['_sold_individually'])) {
if ($_REQUEST['_sold_individually'] == 'yes') {
update_post_meta($post_id, '_sold_individually', 'yes');
} else {
update_post_meta($post_id, '_sold_individually', '');
}
}
// Handle price - remove dates and set to lowest
if ($product->is_type('simple') || $product->is_type('external')) {
$price_changed = false;
if (!empty($_REQUEST['change_regular_price'])) {
$change_regular_price = absint($_REQUEST['change_regular_price']);
$regular_price = esc_attr(stripslashes($_REQUEST['_regular_price']));
switch ($change_regular_price) {
case 1:
$new_price = $regular_price;
break;
case 2:
if (strstr($regular_price, '%')) {
$percent = str_replace('%', '', $regular_price) / 100;
$new_price = $old_regular_price + round($old_regular_price * $percent, wc_get_price_decimals());
} else {
$new_price = $old_regular_price + $regular_price;
}
break;
case 3:
if (strstr($regular_price, '%')) {
$percent = str_replace('%', '', $regular_price) / 100;
$new_price = max(0, $old_regular_price - round($old_regular_price * $percent, wc_get_price_decimals()));
} else {
$new_price = max(0, $old_regular_price - $regular_price);
}
break;
default:
break;
}
if (isset($new_price) && $new_price != $old_regular_price) {
$price_changed = true;
//.........这里部分代码省略.........
示例7: save_variations
/**
* Save meta box data
*
* @deprecated 2.4.0 Deprecated in favor to WC_AJAX::save_variations()
*/
public static function save_variations($post_id, $post)
{
global $wpdb;
$attributes = (array) maybe_unserialize(get_post_meta($post_id, '_product_attributes', true));
if (isset($_POST['variable_sku'])) {
$variable_post_id = $_POST['variable_post_id'];
$variable_sku = $_POST['variable_sku'];
$variable_regular_price = $_POST['variable_regular_price'];
$variable_sale_price = $_POST['variable_sale_price'];
$upload_image_id = $_POST['upload_image_id'];
$variable_download_limit = $_POST['variable_download_limit'];
$variable_download_expiry = $_POST['variable_download_expiry'];
$variable_shipping_class = $_POST['variable_shipping_class'];
$variable_tax_class = isset($_POST['variable_tax_class']) ? $_POST['variable_tax_class'] : array();
$variable_menu_order = $_POST['variation_menu_order'];
$variable_sale_price_dates_from = $_POST['variable_sale_price_dates_from'];
$variable_sale_price_dates_to = $_POST['variable_sale_price_dates_to'];
$variable_weight = isset($_POST['variable_weight']) ? $_POST['variable_weight'] : array();
$variable_length = isset($_POST['variable_length']) ? $_POST['variable_length'] : array();
$variable_width = isset($_POST['variable_width']) ? $_POST['variable_width'] : array();
$variable_height = isset($_POST['variable_height']) ? $_POST['variable_height'] : array();
$variable_enabled = isset($_POST['variable_enabled']) ? $_POST['variable_enabled'] : array();
$variable_is_virtual = isset($_POST['variable_is_virtual']) ? $_POST['variable_is_virtual'] : array();
$variable_is_downloadable = isset($_POST['variable_is_downloadable']) ? $_POST['variable_is_downloadable'] : array();
$variable_manage_stock = isset($_POST['variable_manage_stock']) ? $_POST['variable_manage_stock'] : array();
$variable_stock = isset($_POST['variable_stock']) ? $_POST['variable_stock'] : array();
$variable_backorders = isset($_POST['variable_backorders']) ? $_POST['variable_backorders'] : array();
$variable_stock_status = isset($_POST['variable_stock_status']) ? $_POST['variable_stock_status'] : array();
$variable_description = isset($_POST['variable_description']) ? $_POST['variable_description'] : array();
$max_loop = max(array_keys($_POST['variable_post_id']));
for ($i = 0; $i <= $max_loop; $i++) {
if (!isset($variable_post_id[$i])) {
continue;
}
$variation_id = absint($variable_post_id[$i]);
// Checkboxes
$is_virtual = isset($variable_is_virtual[$i]) ? 'yes' : 'no';
$is_downloadable = isset($variable_is_downloadable[$i]) ? 'yes' : 'no';
$post_status = isset($variable_enabled[$i]) ? 'publish' : 'private';
$manage_stock = isset($variable_manage_stock[$i]) ? 'yes' : 'no';
// Generate a useful post title
$variation_post_title = sprintf(__('Variation #%s of %s', 'woocommerce'), absint($variation_id), esc_html(get_the_title($post_id)));
// Update or Add post
if (!$variation_id) {
$variation = array('post_title' => $variation_post_title, 'post_content' => '', 'post_status' => $post_status, 'post_author' => get_current_user_id(), 'post_parent' => $post_id, 'post_type' => 'product_variation', 'menu_order' => $variable_menu_order[$i]);
$variation_id = wp_insert_post($variation);
do_action('woocommerce_create_product_variation', $variation_id);
} else {
$wpdb->update($wpdb->posts, array('post_status' => $post_status, 'post_title' => $variation_post_title, 'menu_order' => $variable_menu_order[$i]), array('ID' => $variation_id));
do_action('woocommerce_update_product_variation', $variation_id);
}
// Only continue if we have a variation ID
if (!$variation_id) {
continue;
}
// Unique SKU
$sku = get_post_meta($variation_id, '_sku', true);
$new_sku = wc_clean(stripslashes($variable_sku[$i]));
if ('' == $new_sku) {
update_post_meta($variation_id, '_sku', '');
} elseif ($new_sku !== $sku) {
if (!empty($new_sku)) {
$unique_sku = wc_product_has_unique_sku($variation_id, $new_sku);
if (!$unique_sku) {
WC_Admin_Meta_Boxes::add_error(__('Variation SKU must be unique.', 'woocommerce'));
} else {
update_post_meta($variation_id, '_sku', $new_sku);
}
} else {
update_post_meta($variation_id, '_sku', '');
}
}
// Update post meta
update_post_meta($variation_id, '_thumbnail_id', absint($upload_image_id[$i]));
update_post_meta($variation_id, '_virtual', wc_clean($is_virtual));
update_post_meta($variation_id, '_downloadable', wc_clean($is_downloadable));
if (isset($variable_weight[$i])) {
update_post_meta($variation_id, '_weight', '' === $variable_weight[$i] ? '' : wc_format_decimal($variable_weight[$i]));
}
if (isset($variable_length[$i])) {
update_post_meta($variation_id, '_length', '' === $variable_length[$i] ? '' : wc_format_decimal($variable_length[$i]));
}
if (isset($variable_width[$i])) {
update_post_meta($variation_id, '_width', '' === $variable_width[$i] ? '' : wc_format_decimal($variable_width[$i]));
}
if (isset($variable_height[$i])) {
update_post_meta($variation_id, '_height', '' === $variable_height[$i] ? '' : wc_format_decimal($variable_height[$i]));
}
// Stock handling
update_post_meta($variation_id, '_manage_stock', $manage_stock);
// Only update stock status to user setting if changed by the user, but do so before looking at stock levels at variation level
if (!empty($variable_stock_status[$i])) {
wc_update_product_stock_status($variation_id, $variable_stock_status[$i]);
}
if ('yes' === $manage_stock) {
//.........这里部分代码省略.........
示例8: bulk_edit_variations
/**
* Bulk edit variations via AJAX
*/
public static function bulk_edit_variations()
{
ob_start();
check_ajax_referer('bulk-edit-variations', 'security');
// Check permissions again and make sure we have what we need
if (!current_user_can('edit_products') || empty($_POST['product_id']) || empty($_POST['bulk_action'])) {
die(-1);
}
global $wpdb;
$product_id = absint($_POST['product_id']);
$bulk_action = wc_clean($_POST['bulk_action']);
$data = !empty($_POST['data']) ? array_map('wc_clean', $_POST['data']) : array();
$variations = array();
if (apply_filters('woocommerce_bulk_edit_variations_need_children', !in_array($bulk_action, array('variable_weight', 'variable_length', 'variable_width', 'variable_height')))) {
$variations = get_posts(array('post_parent' => $product_id, 'posts_per_page' => -1, 'post_type' => 'product_variation', 'fields' => 'ids', 'post_status' => array('publish', 'private')));
}
switch ($bulk_action) {
case 'toggle_enabled':
foreach ($variations as $variation_id) {
$post_status = get_post_status($variation_id);
$new_status = 'private' === $post_status ? 'publish' : 'private';
$wpdb->update($wpdb->posts, array('post_status' => $new_status), array('ID' => $variation_id));
}
break;
case 'toggle_downloadable':
foreach ($variations as $variation_id) {
$_downloadable = get_post_meta($variation_id, '_downloadable', true);
$is_downloadable = 'no' === $_downloadable ? 'yes' : 'no';
update_post_meta($variation_id, '_downloadable', wc_clean($is_downloadable));
}
break;
case 'toggle_virtual':
foreach ($variations as $variation_id) {
$_virtual = get_post_meta($variation_id, '_virtual', true);
$is_virtual = 'no' === $_virtual ? 'yes' : 'no';
update_post_meta($variation_id, '_virtual', wc_clean($is_virtual));
}
break;
case 'toggle_manage_stock':
foreach ($variations as $variation_id) {
$_manage_stock = get_post_meta($variation_id, '_manage_stock', true);
$is_manage_stock = 'no' === $_manage_stock ? 'yes' : 'no';
update_post_meta($variation_id, '_manage_stock', wc_clean($is_manage_stock));
}
break;
case 'variable_regular_price':
case 'variable_sale_price':
if (empty($data['value'])) {
break;
}
$field = str_replace('variable', '', $bulk_action);
foreach ($variations as $variation_id) {
// Price fields
$regular_price = '_regular_price' === $field ? $data['value'] : get_post_meta($variation_id, '_regular_price', true);
$sale_price = '_sale_price' === $field ? $data['value'] : get_post_meta($variation_id, '_sale_price', true);
// Date fields
$date_from = get_post_meta($variation_id, '_sale_price_dates_from', true);
$date_to = get_post_meta($variation_id, '_sale_price_dates_to', true);
$date_from = !empty($date_from) ? date('Y-m-d', $date_from) : '';
$date_to = !empty($date_to) ? date('Y-m-d', $date_to) : '';
_wc_save_product_price($variation_id, $regular_price, $sale_price, $date_from, $date_to);
}
break;
case 'variable_stock':
if (empty($data['value'])) {
break;
}
$value = wc_clean($data['value']);
foreach ($variations as $variation_id) {
if ('yes' === get_post_meta($variation_id, '_manage_stock', true)) {
wc_update_product_stock($variation_id, wc_stock_amount($value));
} else {
delete_post_meta($variation_id, '_stock');
}
}
break;
case 'variable_weight':
case 'variable_length':
case 'variable_width':
case 'variable_height':
if (empty($data['value'])) {
break;
}
$value = wc_clean($data['value']);
$field = str_replace('variable', '', $bulk_action);
$wpdb->query($wpdb->prepare("\n\t\t\t\t\tUPDATE {$wpdb->postmeta} AS postmeta\n\t\t\t\t\tINNER JOIN {$wpdb->posts} AS posts ON posts.post_parent = %d\n\t\t\t\t\tSET postmeta.meta_value = %s\n\t\t\t\t\tWHERE postmeta.meta_key = '%s'\n\t\t\t\t\tAND postmeta.post_id = posts.ID\n\t\t\t\t ", $product_id, $value, $field));
break;
case 'variable_download_limit':
case 'variable_download_expiry':
if (empty($data['value'])) {
break;
}
$value = wc_clean($data['value']);
$field = str_replace('variable', '', $bulk_action);
foreach ($variations as $variation_id) {
if ('yes' === get_post_meta($variation_id, '_downloadable', true)) {
update_post_meta($variation_id, $field, $value);
//.........这里部分代码省略.........
示例9: woo_vou_update_product_stock
/**
* Update product stock
*
* Handles to Update Product Stock
*
* @package WooCommerce - PDF Vouchers
* @since 2.4.0
*/
public function woo_vou_update_product_stock($product_id = '', $variation_id = '', $voucher_codes = array())
{
//Total avialable voucher code
$avail_total_codes = count($voucher_codes);
if (!empty($variation_id)) {
wc_update_product_stock($variation_id, $avail_total_codes);
} else {
wc_update_product_stock($product_id, $avail_total_codes);
}
}
示例10: update_post_metas
public function update_post_metas()
{
text('Started Updating Product Meta ');
text('current product type : ' . $this->current_product_type);
wp_set_object_terms($this->current_product_id, $this->current_product_type, 'product_type');
if ($this->current_product_type == 'simple') {
$this->set_post_meta($this->current_product_id, $this->current_product['variants'][0]);
$this->add_vendor();
$this->set_product_attribute($this->created_attribute[product_vendor_term], $this->current_product['vendor'], 0, 0, 1, 1);
if (isset($this->current_product['variants'][0]['inventory_quantity']) && $this->current_product['variants'][0]['inventory_quantity'] != null) {
wc_update_product_stock($this->current_product_id, intval($this->current_product['variants'][0]['inventory_quantity']));
} else {
wc_update_product_stock($this->current_product_id, intval(0));
}
text('Adding Product Type ');
$collections = $this->checkCollection($this->current_product['id']);
if (!empty($collections)) {
foreach ($collections as $cname) {
$term_id = $this->create_tax_term($cname, $this->created_attribute[product_type_term]);
wp_set_post_terms($this->current_product_id, $term_id, $this->created_attribute[product_type_term]);
}
$this->set_product_attribute($this->created_attribute[product_type_term], implode(",", $collections), 0, 0, 1, 1);
}
} else {
if ($this->current_product_type == 'variable') {
$others = array();
$collections_set = array();
$ab_key = $this->get_varients_attribute_key();
$custom_meta = array();
foreach ($this->current_product['variants'] as $varK => $varV) {
$variation_post_title = sprintf(__('Variation #%s of %s', 'woocommerce'), $varV['id'], esc_html($this->current_product['title']));
$collections = $this->checkCollection($varV['id']);
$new_variation = array('post_title' => $variation_post_title, 'post_content' => '', 'post_status' => product_status, 'post_author' => product_author, 'post_parent' => $this->current_product_id, 'post_type' => product_varient_post_type);
$variation_id = wp_insert_post($new_variation);
do_action('woocommerce_create_product_variation', $variation_id);
if (!empty($collections)) {
foreach ($collections as $cols) {
$collections_set[] = $collections;
}
$custom_meta[$ab_key['type']] = sanitize_title(stripslashes($collections[0]));
}
if (isset($varV['inventory_quantity']) && $varV['inventory_quantity'] != null) {
wc_update_product_stock($variation_id, intval($varV['inventory_quantity']));
} else {
wc_update_product_stock($variation_id, intval(0));
}
if (!empty($varV['option1']) && $varV['option1'] !== null) {
$others[$this->checkVariationValue($varV['option1'])][] = $varV['option1'];
}
if (!empty($varV['option2']) && $varV['option2'] !== null) {
$others[$this->checkVariationValue($varV['option2'])][] = $varV['option2'];
}
if (!empty($varV['option3']) && $varV['option3'] !== null) {
$others[$this->checkVariationValue($varV['option3'])][] = $varV['option3'];
}
$this->set_post_meta($variation_id, $varV, $custom_meta);
}
}
}
$this->add_vendor();
$this->set_product_attribute($this->created_attribute[product_vendor_term], $this->current_product['vendor'], 0, 0, 1, 1);
$collections = $this->checkCollection($this->current_product['id']);
if (!empty($collections)) {
foreach ($collections as $cname) {
$term_id = $this->create_tax_term($cname, $this->created_attribute[product_type_term]);
wp_set_post_terms($this->current_product_id, $term_id, $this->created_attribute[product_type_term]);
}
$this->set_product_attribute($this->created_attribute[product_type_term], implode(",", $collections), 0, 0, 1, 1);
}
if (!empty($others)) {
foreach ($others as $othk => $othv) {
if (is_array($othv)) {
foreach ($othv as $v) {
$this->create_tax_term($v, $this->created_attribute[$othk]);
}
}
wp_set_object_terms($this->current_product_id, $othv, $this->created_attribute[$othk]);
$this->set_product_attribute($this->created_attribute[$othk], implode(',', $othv));
}
}
$custom_meta['_product_attributes'] = $this->current_product_attribute;
$this->set_post_meta($this->current_product_id, $varV, $custom_meta);
text('Finished Updating Product Meta ');
}
示例11: woo_vou_product_save_data
//.........这里部分代码省略.........
$voucher_codes = isset($_POST[$prefix . 'codes']) ? $this->model->woo_vou_escape_slashes_deep($_POST[$prefix . 'codes']) : '';
update_post_meta($post_id, $prefix . 'codes', $voucher_codes);
$usability = $woo_vou_using_type;
if (isset($_POST[$prefix . 'vendor_user']) && !empty($_POST[$prefix . 'vendor_user']) && $usability == '') {
//if vendor user is set and usability is default
$usability = get_user_meta($_POST[$prefix . 'vendor_user'], $prefix . 'using_type', true);
}
// If usability is default then take it from setting
if ($usability == '') {
$usability = get_option('vou_pdf_usability');
}
update_post_meta($post_id, $prefix . 'using_type', $woo_vou_using_type);
// vendor's Logo
update_post_meta($post_id, $prefix . 'logo', $woo_vou_logo);
// Vendor's Address
update_post_meta($post_id, $prefix . 'address_phone', $this->model->woo_vou_escape_slashes_deep($woo_vou_address_phone, true, true));
// Website URL
update_post_meta($post_id, $prefix . 'website', $this->model->woo_vou_escape_slashes_deep($woo_vou_website));
// Redeem Instructions
update_post_meta($post_id, $prefix . 'how_to_use', $this->model->woo_vou_escape_slashes_deep($woo_vou_how_to_use, true, true));
// update available products count on bases of entered voucher codes
if (isset($_POST[$prefix . 'codes']) && $enable_voucher == 'yes') {
$voucount = '';
$vouchercodes = trim($_POST[$prefix . 'codes'], ',');
if (!empty($vouchercodes)) {
$vouchercodes = explode(',', $vouchercodes);
$voucount = count($vouchercodes);
}
if (empty($usability)) {
// using type is only one time
$avail_total = empty($voucount) ? '0' : $voucount;
// Getting variable product id
$variable_post_id = !empty($_POST['variable_post_id']) ? $_POST['variable_post_id'] : array();
// If product is variable and id's are not blank then update their quantity with blank
if ($product_type == 'variable' && !empty($variable_post_id)) {
// set flag false
$variable_code_flag = false;
foreach ($variable_post_id as $variable_post) {
$variable_is_downloadable = get_post_meta($variable_post, '_downloadable', true);
$variable_codes = get_post_meta($variable_post, $prefix . 'codes', true);
if ($variable_is_downloadable == 'yes' && !empty($variable_codes)) {
// if variation is set as downloadable and vochers codes set at variation level
$variable_code_flag = true;
}
}
if ($variable_code_flag == true) {
// mark this product as variable voucher so we consider it to take vouchers from variations
update_post_meta($post_id, $prefix . 'is_variable_voucher', '1');
} else {
update_post_meta($post_id, $prefix . 'is_variable_voucher', '');
}
foreach ($variable_post_id as $variable_post) {
if ($variable_code_flag != true) {
// if there no voucher codes set on variation level
// update variation manage stock as no
update_post_meta($variable_post, '_manage_stock', 'no');
// Update variation stock qty with blank
update_post_meta($variable_post, '_stock', '');
// Update variation downloadable with yes
update_post_meta($variable_post, '_downloadable', 'yes');
} else {
//update manage stock with yes
update_post_meta($variable_post, '_manage_stock', 'yes');
$variable_voucount = '';
$variable_codes = get_post_meta($variable_post, $prefix . 'codes', true);
$vouchercodes = trim($variable_codes, ',');
if (!empty($vouchercodes)) {
$vouchercodes = explode(',', $vouchercodes);
$variable_voucount = count($vouchercodes);
}
$variable_avail_total = empty($variable_voucount) ? '0' : $variable_voucount;
//update available count on bases of
//update_post_meta( $variable_post, '_stock', $variable_avail_total );
wc_update_product_stock($variable_post, $variable_avail_total);
}
}
}
//update manage stock with yes
update_post_meta($post_id, '_manage_stock', 'yes');
//update available count on bases of
//update_post_meta( $post_id, '_stock', $avail_total );
wc_update_product_stock($post_id, $avail_total);
}
}
//update location and map links
$availlocations = array();
if (isset($_POST[$prefix . 'locations'])) {
$locations = $_POST[$prefix . 'locations'];
$maplinks = $_POST[$prefix . 'map_link'];
for ($i = 0; $i < count($locations); $i++) {
if (!empty($locations[$i]) || !empty($maplinks[$i])) {
//if location or map link is not empty then
$availlocations[$i][$prefix . 'locations'] = $this->model->woo_vou_escape_slashes_deep($locations[$i], true, true);
$availlocations[$i][$prefix . 'map_link'] = $this->model->woo_vou_escape_slashes_deep($maplinks[$i]);
}
}
}
//update location and map links
update_post_meta($post_id, $prefix . 'avail_locations', $availlocations);
}
示例12: bulk_edit_save
//.........这里部分代码省略.........
}
break;
default:
break;
}
if (isset($new_price) && $new_price != $old_regular_price) {
$price_changed = true;
$new_price = round($new_price, wc_get_price_decimals());
$product->set_regular_price($new_price);
}
}
if (!empty($_REQUEST['change_sale_price'])) {
$change_sale_price = absint($_REQUEST['change_sale_price']);
$sale_price = esc_attr(stripslashes($_REQUEST['_sale_price']));
switch ($change_sale_price) {
case 1:
$new_price = $sale_price;
break;
case 2:
if (strstr($sale_price, '%')) {
$percent = str_replace('%', '', $sale_price) / 100;
$new_price = $old_sale_price + $old_sale_price * $percent;
} else {
$new_price = $old_sale_price + $sale_price;
}
break;
case 3:
if (strstr($sale_price, '%')) {
$percent = str_replace('%', '', $sale_price) / 100;
$new_price = max(0, $old_sale_price - $old_sale_price * $percent);
} else {
$new_price = max(0, $old_sale_price - $sale_price);
}
break;
case 4:
if (strstr($sale_price, '%')) {
$percent = str_replace('%', '', $sale_price) / 100;
$new_price = max(0, $product->regular_price - $product->regular_price * $percent);
} else {
$new_price = max(0, $product->regular_price - $sale_price);
}
break;
default:
break;
}
if (isset($new_price) && $new_price != $old_sale_price) {
$price_changed = true;
$new_price = !empty($new_price) || '0' === $new_price ? round($new_price, wc_get_price_decimals()) : '';
$product->set_sale_price($new_price);
}
}
if ($price_changed) {
$product->set_date_on_sale_to('');
$product->set_date_on_sale_from('');
if ($product->get_regular_price() < $product->get_sale_price()) {
$product->set_sale_price('');
}
}
}
// Handle Stock Data
$was_managing_stock = $product->get_manage_stock() ? 'yes' : 'no';
$stock_status = $product->get_stock_status();
$backorders = $product->get_backorders();
$backorders = !empty($_REQUEST['_backorders']) ? wc_clean($_REQUEST['_backorders']) : $backorders;
$stock_status = !empty($_REQUEST['_stock_status']) ? wc_clean($_REQUEST['_stock_status']) : $stock_status;
if (!empty($_REQUEST['_manage_stock'])) {
$manage_stock = 'yes' === wc_clean($_REQUEST['_manage_stock']) && 'grouped' !== $product->product_type ? 'yes' : 'no';
} else {
$manage_stock = $was_managing_stock;
}
$stock_amount = 'yes' === $manage_stock && isset($_REQUEST['_change_stock']) ? wc_stock_amount($_REQUEST['_change_stock']) : '';
if ('yes' === get_option('woocommerce_manage_stock')) {
// Apply product type constraints to stock status
if ($product->is_type('external')) {
// External always in stock
$stock_status = 'instock';
} elseif ($product->is_type('variable')) {
// Stock status is always determined by children
foreach ($product->get_children() as $child_id) {
$child = wc_get_product($child_id);
if (!$product->get_manage_stock()) {
$child->set_stock_status($stock_status);
$child->save();
}
}
$product = WC_Product_Variable::sync($product, false);
}
$product->set_manage_stock($manage_stock);
$product->set_backorders($backorders);
$product->save();
if (!$product->is_type('variable')) {
wc_update_product_stock_status($post_id, $stock_status);
}
wc_update_product_stock($post_id, $stock_amount);
} else {
$product->save();
wc_update_product_stock_status($post_id, $stock_status);
}
do_action('woocommerce_product_bulk_edit_save', $product);
}
示例13: test_wc_update_product_stock
/**
* Test wc_update_product_stock().
*
* @since 2.3
*/
public function test_wc_update_product_stock()
{
// Create product
$product = WC_Helper_Product::create_simple_product();
update_post_meta($product->get_id(), '_manage_stock', 'yes');
wc_update_product_stock($product->get_id(), 5);
$product = new WC_Product_Simple($product->get_id());
$this->assertEquals(5, $product->get_stock_quantity());
// Delete Product
WC_Helper_Product::delete_product($product->get_id());
}
示例14: mp_save_variation
public function mp_save_variation($id, $data)
{
global $wpdb;
/*================= my method*/
$menu_order = 0;
$attributes = (array) maybe_unserialize(get_post_meta($id, '_product_attributes', true));
/*
echo '<pre>';
print_r($attributes);
echo '</pre>';*/
// $data=array_reverse($data);
$cinv = 0;
foreach ($data as $variation_id) {
/*start of loop*/
$variation_id = isset($variation_id) ? absint($variation_id) : 0;
/*if($cinv==0 && isset($_POST['new_added_variation']) && $_POST['new_added_variation']>=1){
$post_title='Variation #'.$id.' of Product';
$product_data=array(
'post_author'=>get_current_user_id(),
'post_content'=>'',
'post_title'=>$post_title,
'post_status'=>'publish',
'post_type'=>'product_variation',
'post_parent'=>$id,
'menu_order'=>''
);
$var_id = wp_insert_post($product_data);
if($var_id!=''){
wp_delete_post($var_id);
}
}
$cinv++;*/
// SKU
if (isset($_POST['wkmp_variable_sku'][$variation_id])) {
$sku = get_post_meta($variation_id, '_sku', true);
$new_sku = wc_clean($_POST['wkmp_variable_sku'][$variation_id]);
$is_sku_unique = wc_product_has_unique_sku($variation_id, $new_sku);
if ('' == $new_sku) {
update_post_meta($variation_id, '_sku', '');
} elseif ($new_sku != $sku && $is_sku_unique) {
if (!empty($new_sku)) {
update_post_meta($variation_id, '_sku', $new_sku);
} else {
update_post_meta($variation_id, '_sku', '');
}
}
}
// Thumbnail
if (isset($_POST['upload_var_img'][$variation_id])) {
$attachment_id = $_POST['upload_var_img'][$variation_id];
if ($attachment_id) {
update_post_meta($variation_id, '_thumbnail_id', $attachment_id);
} else {
// delete_post_meta( $variation_id, '_thumbnail_id' );
update_post_meta($variation_id, '_thumbnail_id', 0);
}
}
// Virtual variation
if (isset($_POST['wkmp_variable_is_virtual'][$variation_id])) {
$is_virtual = $_POST['wkmp_variable_is_virtual'][$variation_id] == 'yes' ? 'yes' : 'no';
update_post_meta($variation_id, '_virtual', $is_virtual);
} else {
update_post_meta($variation_id, '_virtual', 'no');
}
// Downloadable variation
if (isset($_POST['wkmp_variable_is_downloadable'][$variation_id])) {
$is_downloadable = 'yes' == $_POST['wkmp_variable_is_downloadable'][$variation_id] ? 'yes' : 'no';
update_post_meta($variation_id, '_downloadable', $is_downloadable);
} else {
update_post_meta($variation_id, '_downloadable', 'no');
// $is_downloadable = get_post_meta( $variation_id, '_downloadable', true );
$is_downloadable = 'no';
}
/*// Shipping data
$this->mp_save_product_shipping_data( $variation_id, $_POST );*/
// Stock handling
if (isset($_POST['wkmp_variable_manage_stock'][$variation_id])) {
$managing_stock = 'yes' == $_POST['wkmp_variable_manage_stock'][$variation_id] ? 'yes' : 'no';
update_post_meta($variation_id, '_manage_stock', $managing_stock);
} else {
update_post_meta($variation_id, '_manage_stock', 'no');
// $managing_stock = get_post_meta( $variation_id, '_manage_stock', true );
$managing_stock = 'no';
}
// Only update stock status to user setting if changed by the user, but do so before looking at stock levels at variation level
if (isset($_POST['wkmp_variable_stock_status'][$variation_id])) {
$stock_status = 'instock' == $_POST['wkmp_variable_stock_status'][$variation_id] ? 'instock' : 'outofstock';
wc_update_product_stock_status($variation_id, $stock_status);
/*update_post_meta( $variation_id, '_stock_status', $managing_stock );*/
}
if ('yes' === $managing_stock) {
if (isset($_POST['wkmp_variable_backorders'][$variation_id])) {
if ('notify' == $_POST['wkmp_variable_backorders'][$variation_id]) {
$backorders = 'notify';
} else {
$backorders = 'yes' == $_POST['wkmp_variable_backorders'][$variation_id] ? 'yes' : 'no';
}
} else {
$backorders = 'no';
}
//.........这里部分代码省略.........
示例15: dokan_save_variations
function dokan_save_variations($post_id)
{
global $woocommerce, $wpdb;
$attributes = (array) maybe_unserialize(get_post_meta($post_id, '_product_attributes', true));
if (isset($_POST['variable_sku'])) {
$variable_post_id = $_POST['variable_post_id'];
$variable_sku = $_POST['variable_sku'];
$variable_mrp_var = $_POST['_mrp_var'];
$variable_regular_price = $_POST['variable_regular_price'];
$variable_sale_price = $_POST['variable_sale_price'];
$upload_image_id = $_POST['upload_image_id'];
$variable_download_limit = $_POST['variable_download_limit'];
$variable_download_expiry = $_POST['variable_download_expiry'];
$variable_shipping_class = $_POST['variable_shipping_class'];
$variable_tax_class = isset($_POST['variable_tax_class']) ? $_POST['variable_tax_class'] : array();
$variable_menu_order = $_POST['variation_menu_order'];
$variable_sale_price_dates_from = $_POST['variable_sale_price_dates_from'];
$variable_sale_price_dates_to = $_POST['variable_sale_price_dates_to'];
$variable_weight = isset($_POST['variable_weight']) ? $_POST['variable_weight'] : array();
$variable_length = isset($_POST['variable_length']) ? $_POST['variable_length'] : array();
$variable_width = isset($_POST['variable_width']) ? $_POST['variable_width'] : array();
$variable_height = isset($_POST['variable_height']) ? $_POST['variable_height'] : array();
$variable_stock = isset($_POST['variable_stock']) ? $_POST['variable_stock'] : array();
$variable_enabled = isset($_POST['variable_enabled']) ? $_POST['variable_enabled'] : array();
$variable_is_virtual = isset($_POST['variable_is_virtual']) ? $_POST['variable_is_virtual'] : array();
$variable_is_downloadable = isset($_POST['variable_is_downloadable']) ? $_POST['variable_is_downloadable'] : array();
$max_loop = max(array_keys($_POST['variable_post_id']));
for ($i = 0; $i <= $max_loop; $i++) {
if (!isset($variable_post_id[$i])) {
continue;
}
$variation_id = absint($variable_post_id[$i]);
// Virtal/Downloadable
$is_virtual = isset($variable_is_virtual[$i]) ? 'yes' : 'no';
$is_downloadable = isset($variable_is_downloadable[$i]) ? 'yes' : 'no';
$manage_stock = isset($variable_stock[$i]) ? 'yes' : 'no';
// Enabled or disabled
$post_status = isset($variable_enabled[$i]) ? 'publish' : 'private';
// Generate a useful post title
$variation_post_title = sprintf(__('Variation #%s of %s', 'woocommerce'), absint($variation_id), esc_html(get_the_title($post_id)));
// Update or Add post
if (!$variation_id) {
$variation = array('post_title' => $variation_post_title, 'post_content' => '', 'post_status' => $post_status, 'post_author' => get_current_user_id(), 'post_parent' => $post_id, 'post_type' => 'product_variation', 'menu_order' => $variable_menu_order[$i]);
$variation_id = wp_insert_post($variation);
do_action('woocommerce_create_product_variation', $variation_id);
} else {
$wpdb->update($wpdb->posts, array('post_status' => $post_status, 'post_title' => $variation_post_title, 'menu_order' => $variable_menu_order[$i]), array('ID' => $variation_id));
do_action('woocommerce_update_product_variation', $variation_id);
}
// Update post meta
update_post_meta($variation_id, '_sku', wc_clean($variable_sku[$i]));
update_post_meta($variation_id, '_thumbnail_id', absint($upload_image_id[$i]));
update_post_meta($variation_id, '_virtual', wc_clean($is_virtual));
update_post_meta($variation_id, '_downloadable', wc_clean($is_downloadable));
update_post_meta($variation_id, '_manage_stock', wc_clean($manage_stock));
if (isset($variable_weight[$i])) {
update_post_meta($variation_id, '_weight', $variable_weight[$i] === '' ? '' : wc_format_decimal($variable_weight[$i]));
}
if (isset($variable_length[$i])) {
update_post_meta($variation_id, '_length', $variable_length[$i] === '' ? '' : wc_format_decimal($variable_length[$i]));
}
if (isset($variable_width[$i])) {
update_post_meta($variation_id, '_width', $variable_width[$i] === '' ? '' : wc_format_decimal($variable_width[$i]));
}
if (isset($variable_height[$i])) {
update_post_meta($variation_id, '_height', $variable_height[$i] === '' ? '' : wc_format_decimal($variable_height[$i]));
}
// Stock handling
if (isset($variable_stock[$i])) {
wc_update_product_stock($variation_id, wc_clean($variable_stock[$i]));
}
// Price handling
$mrp = wc_format_decimal($variable_mrp_var[$i]);
$regular_price = wc_format_decimal($variable_regular_price[$i]);
$sale_price = $variable_sale_price[$i] === '' ? '' : wc_format_decimal($variable_sale_price[$i]);
$date_from = wc_clean($variable_sale_price_dates_from[$i]);
$date_to = wc_clean($variable_sale_price_dates_to[$i]);
update_post_meta($variation_id, '_regular_price', $regular_price);
update_post_meta($variation_id, '_sale_price', $sale_price);
update_post_meta($variation_id, '_list_price_mrp', $mrp);
// Save Dates
if ($date_from) {
update_post_meta($variation_id, '_sale_price_dates_from', strtotime($date_from));
} else {
update_post_meta($variation_id, '_sale_price_dates_from', '');
}
if ($date_to) {
update_post_meta($variation_id, '_sale_price_dates_to', strtotime($date_to));
} else {
update_post_meta($variation_id, '_sale_price_dates_to', '');
}
if ($date_to && !$date_from) {
update_post_meta($variation_id, '_sale_price_dates_from', strtotime('NOW', current_time('timestamp')));
}
// Update price if on sale
if ($sale_price != '' && $date_to == '' && $date_from == '') {
update_post_meta($variation_id, '_price', $sale_price);
} else {
update_post_meta($variation_id, '_price', $regular_price);
}
//.........这里部分代码省略.........