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


PHP WC_Product_Variation::set_props方法代码示例

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


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

示例1: save_variations

 /**
  * Save meta box data.
  *
  * @param int $post_id
  * @param WP_Post $post
  */
 public static function save_variations($post_id, $post)
 {
     if (isset($_POST['variable_post_id'])) {
         $parent = wc_get_product($post_id);
         $max_loop = max(array_keys($_POST['variable_post_id']));
         $data_store = $parent->get_data_store();
         $data_store->sort_all_product_variations($parent->get_id());
         for ($i = 0; $i <= $max_loop; $i++) {
             if (!isset($_POST['variable_post_id'][$i])) {
                 continue;
             }
             $variation_id = absint($_POST['variable_post_id'][$i]);
             $variation = new WC_Product_Variation($variation_id);
             $errors = $variation->set_props(array('status' => isset($_POST['variable_enabled'][$i]) ? 'publish' : 'private', 'menu_order' => wc_clean($_POST['variation_menu_order'][$i]), 'regular_price' => wc_clean($_POST['variable_regular_price'][$i]), 'sale_price' => wc_clean($_POST['variable_sale_price'][$i]), 'virtual' => isset($_POST['variable_is_virtual'][$i]), 'downloadable' => isset($_POST['variable_is_downloadable'][$i]), 'date_on_sale_from' => wc_clean($_POST['variable_sale_price_dates_from'][$i]), 'date_on_sale_to' => wc_clean($_POST['variable_sale_price_dates_to'][$i]), 'description' => wp_kses_post(wc_sanitize_textarea($_POST['variable_description'][$i])), 'download_limit' => wc_clean($_POST['variable_download_limit'][$i]), 'download_expiry' => wc_clean($_POST['variable_download_expiry'][$i]), 'downloads' => self::prepare_downloads(isset($_POST['_wc_variation_file_names'][$variation_id]) ? $_POST['_wc_variation_file_names'][$variation_id] : array(), isset($_POST['_wc_variation_file_urls'][$variation_id]) ? $_POST['_wc_variation_file_urls'][$variation_id] : array(), isset($_POST['_wc_variation_file_hashes'][$variation_id]) ? $_POST['_wc_variation_file_hashes'][$variation_id] : array()), 'manage_stock' => isset($_POST['variable_manage_stock'][$i]), 'stock_quantity' => wc_clean($_POST['variable_stock'][$i]), 'backorders' => wc_clean($_POST['variable_backorders'][$i]), 'stock_status' => wc_clean($_POST['variable_stock_status'][$i]), 'image_id' => wc_clean($_POST['upload_image_id'][$i]), 'attributes' => self::prepare_set_attributes($parent->get_attributes(), 'attribute_', $i), 'sku' => isset($_POST['variable_sku'][$i]) ? wc_clean($_POST['variable_sku'][$i]) : '', 'weight' => isset($_POST['variable_weight'][$i]) ? wc_clean($_POST['variable_weight'][$i]) : '', 'length' => isset($_POST['variable_length'][$i]) ? wc_clean($_POST['variable_length'][$i]) : '', 'width' => isset($_POST['variable_width'][$i]) ? wc_clean($_POST['variable_width'][$i]) : '', 'height' => isset($_POST['variable_height'][$i]) ? wc_clean($_POST['variable_height'][$i]) : '', 'shipping_class_id' => wc_clean($_POST['variable_shipping_class'][$i]), 'tax_class' => wc_clean($_POST['variable_tax_class'][$i])));
             if (is_wp_error($errors)) {
                 WC_Admin_Meta_Boxes::add_error($errors->get_error_message());
             }
             $variation->save();
             do_action('woocommerce_save_product_variation', $variation_id, $i);
         }
     }
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:28,代码来源:class-wc-meta-box-product-data.php


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