当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Product_Variable::sync_stock_status方法代码示例

本文整理汇总了PHP中WC_Product_Variable::sync_stock_status方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product_Variable::sync_stock_status方法的具体用法?PHP WC_Product_Variable::sync_stock_status怎么用?PHP WC_Product_Variable::sync_stock_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Product_Variable的用法示例。


在下文中一共展示了WC_Product_Variable::sync_stock_status方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save


//.........这里部分代码省略.........
             update_post_meta($post_id, '_stock', '');
         }
     } elseif ('variable' !== $product_type) {
         wc_update_product_stock_status($post_id, wc_clean($_POST['_stock_status']));
     }
     // Cross sells and upsells
     $upsells = isset($_POST['upsell_ids']) ? array_filter(array_map('intval', explode(',', $_POST['upsell_ids']))) : array();
     $crosssells = isset($_POST['crosssell_ids']) ? array_filter(array_map('intval', explode(',', $_POST['crosssell_ids']))) : array();
     update_post_meta($post_id, '_upsell_ids', $upsells);
     update_post_meta($post_id, '_crosssell_ids', $crosssells);
     // Downloadable options
     if ('yes' == $is_downloadable) {
         $_download_limit = absint($_POST['_download_limit']);
         if (!$_download_limit) {
             $_download_limit = '';
             // 0 or blank = unlimited
         }
         $_download_expiry = absint($_POST['_download_expiry']);
         if (!$_download_expiry) {
             $_download_expiry = '';
             // 0 or blank = unlimited
         }
         // file paths will be stored in an array keyed off md5(file path)
         $files = array();
         if (isset($_POST['_wc_file_urls'])) {
             $file_names = isset($_POST['_wc_file_names']) ? $_POST['_wc_file_names'] : array();
             $file_urls = isset($_POST['_wc_file_urls']) ? wp_unslash(array_map('trim', $_POST['_wc_file_urls'])) : array();
             $file_url_size = sizeof($file_urls);
             $allowed_file_types = apply_filters('woocommerce_downloadable_file_allowed_mime_types', get_allowed_mime_types());
             for ($i = 0; $i < $file_url_size; $i++) {
                 if (!empty($file_urls[$i])) {
                     // Find type and file URL
                     if (0 === strpos($file_urls[$i], 'http')) {
                         $file_is = 'absolute';
                         $file_url = esc_url_raw($file_urls[$i]);
                     } elseif ('[' === substr($file_urls[$i], 0, 1) && ']' === substr($file_urls[$i], -1)) {
                         $file_is = 'shortcode';
                         $file_url = wc_clean($file_urls[$i]);
                     } else {
                         $file_is = 'relative';
                         $file_url = wc_clean($file_urls[$i]);
                     }
                     $file_name = wc_clean($file_names[$i]);
                     $file_hash = md5($file_url);
                     // Validate the file extension
                     if (in_array($file_is, array('absolute', 'relative'))) {
                         $file_type = wp_check_filetype(strtok($file_url, '?'), $allowed_file_types);
                         $parsed_url = parse_url($file_url, PHP_URL_PATH);
                         $extension = pathinfo($parsed_url, PATHINFO_EXTENSION);
                         if (!empty($extension) && !in_array($file_type['type'], $allowed_file_types)) {
                             WC_Admin_Meta_Boxes::add_error(sprintf(__('The downloadable file %s cannot be used as it does not have an allowed file type. Allowed types include: %s', 'woocommerce'), '<code>' . basename($file_url) . '</code>', '<code>' . implode(', ', array_keys($allowed_file_types)) . '</code>'));
                             continue;
                         }
                     }
                     // Validate the file exists
                     if ('relative' === $file_is) {
                         $_file_url = $file_url;
                         if ('..' === substr($file_url, 0, 2) || '/' !== substr($file_url, 0, 1)) {
                             $_file_url = realpath(ABSPATH . $file_url);
                         }
                         if (!apply_filters('woocommerce_downloadable_file_exists', file_exists($_file_url), $file_url)) {
                             WC_Admin_Meta_Boxes::add_error(sprintf(__('The downloadable file %s cannot be used as it does not exist on the server.', 'woocommerce'), '<code>' . $file_url . '</code>'));
                             continue;
                         }
                     }
                     $files[$file_hash] = array('name' => $file_name, 'file' => $file_url);
                 }
             }
         }
         // grant permission to any newly added files on any existing orders for this product prior to saving
         do_action('woocommerce_process_product_file_download_paths', $post_id, 0, $files);
         update_post_meta($post_id, '_downloadable_files', $files);
         update_post_meta($post_id, '_download_limit', $_download_limit);
         update_post_meta($post_id, '_download_expiry', $_download_expiry);
         if (isset($_POST['_download_type'])) {
             update_post_meta($post_id, '_download_type', wc_clean($_POST['_download_type']));
         }
     }
     // Product url
     if ('external' == $product_type) {
         if (isset($_POST['_product_url'])) {
             update_post_meta($post_id, '_product_url', esc_url_raw($_POST['_product_url']));
         }
         if (isset($_POST['_button_text'])) {
             update_post_meta($post_id, '_button_text', wc_clean($_POST['_button_text']));
         }
     }
     // Save variations
     if ('variable' == $product_type) {
         // Update parent if variable so price sorting works and stays in sync with the cheapest child
         WC_Product_Variable::sync($post_id);
         WC_Product_Variable::sync_stock_status($post_id);
     }
     // Update version after saving
     update_post_meta($post_id, '_product_version', WC_VERSION);
     // Do action for product type
     do_action('woocommerce_process_product_meta_' . $product_type, $post_id);
     // Clear cache/transients
     wc_delete_product_transients($post_id);
 }
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:101,代码来源:class-wc-meta-box-product-data.php

示例2: set_stock_status

 /**
  * set_stock_status function.
  */
 public function set_stock_status($status)
 {
     $status = 'outofstock' === $status ? 'outofstock' : 'instock';
     // Sanity check
     if (true === $this->managing_stock()) {
         if (!$this->backorders_allowed() && $this->get_stock_quantity() <= get_option('woocommerce_notify_no_stock_amount')) {
             $status = 'outofstock';
         }
     } elseif ('parent' === $this->managing_stock()) {
         if (!$this->parent->backorders_allowed() && $this->parent->get_stock_quantity() <= get_option('woocommerce_notify_no_stock_amount')) {
             $status = 'outofstock';
         }
     }
     if (update_post_meta($this->variation_id, '_stock_status', $status)) {
         do_action('woocommerce_variation_set_stock_status', $this->variation_id, $status);
         if (true === $this->managing_stock()) {
             WC_Product_Variable::sync_stock_status($this->id);
         }
     }
 }
开发者ID:noman1059,项目名称:woocommerce,代码行数:23,代码来源:class-wc-product-variation.php

示例3: edit_product

 /**
  * Edit a product
  *
  * @since 2.2
  * @param int $id the product ID
  * @param array $data
  * @return array
  */
 public function edit_product($id, $data)
 {
     try {
         if (!isset($data['product'])) {
             throw new WC_API_Exception('woocommerce_api_missing_product_data', sprintf(__('No %1$s data specified to edit %1$s', 'woocommerce'), 'product'), 400);
         }
         $data = $data['product'];
         $id = $this->validate_request($id, 'product', 'edit');
         if (is_wp_error($id)) {
             return $id;
         }
         $data = apply_filters('woocommerce_api_edit_product_data', $data, $this);
         // Product title.
         if (isset($data['title'])) {
             wp_update_post(array('ID' => $id, 'post_title' => wc_clean($data['title'])));
         }
         // Product name (slug).
         if (isset($data['name'])) {
             wp_update_post(array('ID' => $id, 'post_name' => sanitize_title($data['name'])));
         }
         // Product status.
         if (isset($data['status'])) {
             wp_update_post(array('ID' => $id, 'post_status' => wc_clean($data['status'])));
         }
         // Product short description.
         if (isset($data['short_description'])) {
             // Enable short description html tags.
             $post_excerpt = isset($data['enable_html_short_description']) && true === $data['enable_html_short_description'] ? $data['short_description'] : wc_clean($data['short_description']);
             wp_update_post(array('ID' => $id, 'post_excerpt' => $post_excerpt));
         }
         // Product description.
         if (isset($data['description'])) {
             // Enable description html tags.
             $post_content = isset($data['enable_html_description']) && true === $data['enable_html_description'] ? $data['description'] : wc_clean($data['description']);
             wp_update_post(array('ID' => $id, 'post_content' => $post_content));
         }
         // Menu order.
         if (isset($data['menu_order'])) {
             wp_update_post(array('ID' => $id, 'menu_order' => intval($data['menu_order'])));
         }
         // Validate the product type.
         if (isset($data['type']) && !in_array(wc_clean($data['type']), array_keys(wc_get_product_types()))) {
             throw new WC_API_Exception('woocommerce_api_invalid_product_type', sprintf(__('Invalid product type - the product type must be any of these: %s', 'woocommerce'), implode(', ', array_keys(wc_get_product_types()))), 400);
         }
         // Check for featured/gallery images, upload it and set it.
         if (isset($data['images'])) {
             $this->save_product_images($id, $data['images']);
         }
         // Save product meta fields.
         $this->save_product_meta($id, $data);
         // Save variations.
         $product = get_product($id);
         if ($product->is_type('variable')) {
             if (isset($data['variations']) && is_array($data['variations'])) {
                 $this->save_variations($id, $data);
             } else {
                 // Just sync variations
                 WC_Product_Variable::sync($id);
                 WC_Product_Variable::sync_stock_status($id);
             }
         }
         do_action('woocommerce_api_edit_product', $id, $data);
         // Clear cache/transients.
         wc_delete_product_transients($id);
         return $this->get_product($id);
     } catch (WC_API_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
     }
 }
开发者ID:johnulist,项目名称:woocommerce,代码行数:77,代码来源:class-wc-api-products.php

示例4: 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;
//.........这里部分代码省略.........
开发者ID:vkolova,项目名称:bgscena,代码行数:101,代码来源:class-wc-admin-post-types.php

示例5: fixVariableStockStatus

 public function fixVariableStockStatus()
 {
     // get all parent variations
     $args = array('post_type' => 'product', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => array('variable'))));
     $query = new WP_Query($args);
     $parent_variations = $query->posts;
     // loop products
     foreach ($parent_variations as $post) {
         // $this->fixVariableStockStatusForProduct( $post->ID );
         WC_Product_Variable::sync_stock_status($post->ID);
     }
 }
开发者ID:imranshuvo,项目名称:wp-lister-for-amazon,代码行数:12,代码来源:ToolsPage.php

示例6: update_post_meta_fields

 /**
  * Update post meta fields.
  *
  * @param WP_Post $post
  * @param WP_REST_Request $request
  * @return bool|WP_Error
  */
 protected function update_post_meta_fields($post, $request)
 {
     try {
         $product = wc_get_product($post);
         // Check for featured/gallery images, upload it and set it.
         if (isset($request['images'])) {
             $this->save_product_images($product->id, $request['images']);
         }
         // Save product meta fields.
         $this->save_product_meta($product, $request);
         // Save variations.
         if ($product->is_type('variable')) {
             if (isset($request['variations']) && is_array($request['variations'])) {
                 $this->save_variations_data($product, $request);
             } else {
                 // Just sync variations.
                 WC_Product_Variable::sync($product->id);
                 WC_Product_Variable::sync_stock_status($product->id);
             }
         }
         return true;
     } catch (WC_REST_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
     }
 }
开发者ID:pelmered,项目名称:woocommerce,代码行数:32,代码来源:class-wc-rest-products-controller.php


注:本文中的WC_Product_Variable::sync_stock_status方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。