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


PHP WC_Product::backorders_allowed方法代码示例

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


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

示例1: get_product_data

 /**
  * Get standard product data that applies to every product type
  *
  * @since 2.1
  * @param WC_Product $product
  * @return array
  */
 private function get_product_data($product)
 {
     return array('title' => $product->get_name(), 'id' => $product->get_id(), 'created_at' => $this->server->format_datetime($product->get_date_created(), false, true), 'updated_at' => $this->server->format_datetime($product->get_date_modified(), false, true), 'type' => $product->get_type(), 'status' => $product->get_status(), 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => wc_format_decimal($product->get_price(), 2), 'regular_price' => wc_format_decimal($product->get_regular_price(), 2), 'sale_price' => $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->get_catalog_visibility(), 'on_sale' => $product->is_on_sale(), 'weight' => $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : null, 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height(), 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => apply_filters('the_content', $product->get_description()), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'categories' => wc_get_object_terms($product->get_id(), 'product_cat', 'name'), 'tags' => wc_get_object_terms($product->get_id(), 'product_tag', 'name'), 'images' => $this->get_images($product), 'featured_src' => wp_get_attachment_url(get_post_thumbnail_id($product->get_id())), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'purchase_note' => apply_filters('the_content', $product->get_purchase_note()), 'total_sales' => $product->get_total_sales(), 'variations' => array(), 'parent' => array());
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:11,代码来源:class-wc-api-products.php

示例2: switch

 /**
  * Bundled product availability that takes quantity into account.
  *
  * @param  WC_Product   $product    the product
  * @param  int          $quantity   the quantity
  * @return array                    availability data
  */
 function get_bundled_product_availability($product, $quantity)
 {
     $availability = $class = '';
     if ($product->managing_stock()) {
         if ($product->is_in_stock() && $product->get_total_stock() > get_option('woocommerce_notify_no_stock_amount') && $product->get_total_stock() >= $quantity) {
             switch (get_option('woocommerce_stock_format')) {
                 case 'no_amount':
                     $availability = __('In stock', 'woocommerce');
                     break;
                 case 'low_amount':
                     if ($product->get_total_stock() <= get_option('woocommerce_notify_low_stock_amount')) {
                         $availability = sprintf(__('Only %s left in stock', 'woocommerce'), $product->get_total_stock());
                         if ($product->backorders_allowed() && $product->backorders_require_notification()) {
                             $availability .= ' ' . __('(can be backordered)', 'woocommerce');
                         }
                     } else {
                         $availability = __('In stock', 'woocommerce');
                     }
                     break;
                 default:
                     $availability = sprintf(__('%s in stock', 'woocommerce'), $product->get_total_stock());
                     if ($product->backorders_allowed() && $product->backorders_require_notification()) {
                         $availability .= ' ' . __('(can be backordered)', 'woocommerce');
                     }
                     break;
             }
             $class = 'in-stock';
         } elseif ($product->backorders_allowed() && $product->backorders_require_notification()) {
             if ($product->get_total_stock() >= $quantity || get_option('woocommerce_stock_format') == 'no_amount') {
                 $availability = __('Available on backorder', 'woocommerce');
             } else {
                 $availability = __('Available on backorder', 'woocommerce') . ' ' . sprintf(__('(only %s left in stock)', 'woocommerce-product-bundles'), $product->get_total_stock());
             }
             $class = 'available-on-backorder';
         } elseif ($product->backorders_allowed()) {
             $availability = __('In stock', 'woocommerce');
             $class = 'in-stock';
         } else {
             if ($product->is_in_stock() && $product->get_total_stock() > get_option('woocommerce_notify_no_stock_amount')) {
                 if (get_option('woocommerce_stock_format') == 'no_amount') {
                     $availability = __('Insufficient stock', 'woocommerce-product-bundles');
                 } else {
                     $availability = __('Insufficient stock', 'woocommerce-product-bundles') . ' ' . sprintf(__('(only %s left in stock)', 'woocommerce-product-bundles'), $product->get_total_stock());
                 }
                 $class = 'out-of-stock';
             } else {
                 $availability = __('Out of stock', 'woocommerce');
                 $class = 'out-of-stock';
             }
         }
     } elseif (!$product->is_in_stock()) {
         $availability = __('Out of stock', 'woocommerce');
         $class = 'out-of-stock';
     }
     _deprecated_function('get_bundled_product_availability', '4.8.8', 'WC_Bundled_Item::get_availability()');
     return apply_filters('woocommerce_get_bundled_product_availability', array('availability' => $availability, 'class' => $class), $product);
 }
开发者ID:ajay786singh,项目名称:viriditas-1,代码行数:64,代码来源:class-wc-pb-helpers.php

示例3: get_product_data

 /**
  * Get standard product data that applies to every product type
  *
  * @since 2.1
  * @param WC_Product $product
  * @return WC_Product
  */
 private function get_product_data($product)
 {
     return array('title' => $product->get_title(), 'id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'created_at' => $this->server->format_datetime($product->get_post_data()->post_date_gmt), 'updated_at' => $this->server->format_datetime($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->visibility, 'on_sale' => $product->is_on_sale(), 'product_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'weight' => $product->get_weight() ? $product->get_weight() : null, 'dimensions' => array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->post->post_parent, 'categories' => wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')), 'tags' => wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')), 'images' => $this->get_images($product), 'featured_src' => (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id)), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => (int) $product->download_limit, 'download_expiry' => (int) $product->download_expiry, 'download_type' => $product->download_type, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->purchase_note))), 'total_sales' => metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0, 'variations' => array(), 'parent' => array(), 'grouped_products' => array());
 }
开发者ID:haltaction,项目名称:woocommerce,代码行数:11,代码来源:class-wc-api-products.php

示例4: get_quantity_range

 /**
  * Get the min/max quantity range for this given product.  At least, do
  * the best we can.  The issue is that this is controlled ultimately by
  * template files, which could be changed by the user/theme.
  *
  * @see woocommerce-template.php woocommerce_quantity_input()
  * @see woocommerce/templates/single-product/add-to-cart/simple.php
  * @see woocommerce/templates/single-product/add-to-cart/variable.php
  *
  * @since 3.0
  * @param WC_Product $product the product
  * @return array associative array with keys 'min_value' and 'max_value'
  */
 public static function get_quantity_range($product)
 {
     // get the quantity min/max for this product
     $defaults = array('input_name' => 'quantity', 'input_value' => '1', 'max_value' => '', 'min_value' => '0');
     $args = array();
     if ($product->is_type('simple')) {
         $args = array('min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity());
     }
     return apply_filters('woocommerce_quantity_input_args', wp_parse_args($args, $defaults));
 }
开发者ID:abcode619,项目名称:wpstuff,代码行数:23,代码来源:class-wc-price-calculator-product.php

示例5:

 /**
  * Reduce stock level of the product
  *
  * @param   int		$by		Amount to reduce by
  */
 function reduce_stock($by = 1)
 {
     global $woocommerce;
     if ($this->variation_has_stock) {
         if ($this->managing_stock()) {
             $this->stock = $this->stock - $by;
             $this->total_stock = $this->total_stock - $by;
             update_post_meta($this->variation_id, '_stock', $this->stock);
             $woocommerce->clear_product_transients($this->id);
             // Clear transient
             // Check parents out of stock attribute
             if (!$this->is_in_stock()) {
                 // Check parent
                 $parent_product = new WC_Product($this->id);
                 // Only continue if the parent has backorders off
                 if (!$parent_product->backorders_allowed() && $parent_product->get_total_stock() <= 0) {
                     update_post_meta($this->id, '_stock_status', 'outofstock');
                 }
             }
             return $this->stock;
         }
     } else {
         return parent::reduce_stock($by);
     }
 }
开发者ID:eddiewilson,项目名称:new-ke,代码行数:30,代码来源:class-wc-product-variation.php

示例6: strtotime

 } else {
     $end_date = strtotime(tribe_get_end_date(get_the_ID(), false, 'Y-m-d G:i') . $gmt_offset);
 }
 $start_date = null;
 if (!empty($ticket->start_date)) {
     $start_date = strtotime($ticket->start_date . $gmt_offset);
 }
 if ((empty($start_date) || time() > $start_date) && (empty($end_date) || time() < $end_date)) {
     $is_there_any_product = true;
     echo sprintf('<input type="hidden" name="product_id[]" value="%d">', $ticket->ID);
     echo '<tr>';
     echo '<td class="woocommerce">';
     if ($product->is_in_stock()) {
         // Max quantity will be left open if backorders allowed, restricted to 1 if the product is
         // constrained to be sold individually or else set to the available stock quantity
         $max_quantity = $product->backorders_allowed() ? '' : $product->get_stock_quantity();
         $max_quantity = $product->is_sold_individually() ? 1 : $max_quantity;
         woocommerce_quantity_input(array('input_name' => 'quantity_' . $ticket->ID, 'input_value' => 0, 'min_value' => 0, 'max_value' => $max_quantity));
         $is_there_any_product_to_sell = true;
     } else {
         echo '<span class="tickets_nostock">' . esc_html__('Out of stock!', 'tribe-wootickets') . '</span>';
     }
     echo '</td>';
     echo '<td nowrap="nowrap" class="tickets_name">';
     echo $ticket->name;
     echo '</td>';
     echo '<td class="tickets_price">';
     echo $this->get_price_html($product);
     //echo '<a class="member_discount nav_login" href="';
     //echo esc_url(home_url('/'));
     //echo 'wp-admin';
开发者ID:pellio11,项目名称:ns-select-project,代码行数:31,代码来源:tickets.php

示例7: foreach

 function process_qty()
 {
     global $woocommerce;
     // Save quantities
     if (!empty($_POST['stock_quantity']) && !empty($_POST['save_stock'])) {
         check_admin_referer('save', 'wc-stock-management');
         $quantities = $_POST['stock_quantity'];
         $current_quantities = $_POST['current_stock_quantity'];
         foreach ($quantities as $id => $qty) {
             if ($qty == '') {
                 continue;
             }
             if (isset($current_quantities[$id])) {
                 // Check the qty has not changed since showing the form
                 $current_stock = (int) get_post_meta($id, '_stock', true);
                 if ($current_stock == $current_quantities[$id]) {
                     $post = get_post($id);
                     // Format $qty
                     $qty = (int) $qty;
                     // Update stock amount
                     update_post_meta($id, '_stock', $qty);
                     // Update stock status
                     if ($post->post_type == 'product') {
                         // Update manage stock variable for products
                         update_post_meta($id, '_manage_stock', 'yes');
                         if (function_exists('get_product')) {
                             $product = get_product($post->ID);
                         } else {
                             $product = new WC_Product($post->ID);
                         }
                         if ($product->managing_stock() && !$product->backorders_allowed() && $product->get_total_stock() <= 0) {
                             update_post_meta($post->ID, '_stock_status', 'outofstock');
                         } elseif ($product->managing_stock() && ($product->backorders_allowed() || $product->get_total_stock() > 0)) {
                             update_post_meta($post->ID, '_stock_status', 'instock');
                         }
                         $woocommerce->clear_product_transients($post->ID);
                         // Clear transient
                     } else {
                         if (function_exists('get_product')) {
                             $product = get_product($post->post_parent);
                         } else {
                             $product = new WC_Product($post->post_parent);
                         }
                         if ($product->managing_stock() && !$product->backorders_allowed() && $product->get_total_stock() <= 0) {
                             update_post_meta($post->post_parent, '_stock_status', 'outofstock');
                         } elseif ($product->managing_stock() && ($product->backorders_allowed() || $product->get_total_stock() > 0)) {
                             update_post_meta($post->post_parent, '_stock_status', 'instock');
                         }
                         $woocommerce->clear_product_transients($post->post_parent);
                         // Clear transient
                     }
                 } else {
                     $this->messages[] = sprintf(__('Product # %s was not updated - the stock amount has changed since posting.', 'wc_stock_management'), $id);
                 }
             }
         }
         $this->messages[] = __('Stock quantities saved.', 'wc_stock_management');
     }
 }
开发者ID:iplaydu,项目名称:Bob-Ellis-Shoes,代码行数:59,代码来源:bulk-stock-management.php

示例8: get_product_from_post

 private function get_product_from_post($post_id)
 {
     $woocommerce_ver_below_2_1 = false;
     if (version_compare(WOOCOMMERCE_VERSION, '2.1', '<')) {
         $woocommerce_ver_below_2_1 = true;
     }
     if ($woocommerce_ver_below_2_1) {
         $product = new WC_Product_Simple($post_id);
     } else {
         $product = new WC_Product($post_id);
     }
     //$post_categories = wp_get_post_categories( $post_id );
     //$categories = get_the_category();
     try {
         $thumbnail = $product->get_image();
         if ($thumbnail) {
             if (preg_match('/data-lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                 $thumbnail = $match[1];
             } else {
                 if (preg_match('/data-lazy-original="([^\\"]+)"/s', $thumbnail, $match)) {
                     $thumbnail = $match[1];
                 } else {
                     if (preg_match('/lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                         // Animate Lazy Load Wordpress Plugin
                         $thumbnail = $match[1];
                     } else {
                         if (preg_match('/data-echo="([^\\"]+)"/s', $thumbnail, $match)) {
                             $thumbnail = $match[1];
                         } else {
                             preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail, $result);
                             $thumbnail = array_pop($result);
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $err_msg = "exception raised in thumbnails";
         self::send_error_report($err_msg);
         $thumbnail = '';
     }
     // handling scheduled sale price update
     if (!$woocommerce_ver_below_2_1) {
         $sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true);
         $sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true);
         if ($sale_price_dates_from || $sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, null);
         }
         if ($sale_price_dates_from) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_from);
         }
         if ($sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_to);
         }
     }
     $product_tags = array();
     foreach (wp_get_post_terms($post_id, 'product_tag') as $tag) {
         $product_tags[] = $tag->name;
     }
     $product_brands = array();
     if (taxonomy_exists('product_brand')) {
         foreach (wp_get_post_terms($post_id, 'product_brand') as $brand) {
             $product_brands[] = $brand->name;
         }
     }
     $taxonomies = array();
     try {
         $all_taxonomies = get_option('wcis_taxonomies');
         if (is_array($all_taxonomies)) {
             foreach ($all_taxonomies as $taxonomy) {
                 if (taxonomy_exists($taxonomy) && !array_key_exists($taxonomy, $taxonomies)) {
                     foreach (wp_get_post_terms($post_id, $taxonomy) as $taxonomy_value) {
                         if (!array_key_exists($taxonomy, $taxonomies)) {
                             $taxonomies[$taxonomy] = array();
                         }
                         $taxonomies[$taxonomy][] = $taxonomy_value->name;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $acf_fields = array();
     try {
         if (class_exists('acf') && function_exists('get_field')) {
             $all_acf_fields = get_option('wcis_acf_fields');
             if (is_array($all_acf_fields)) {
                 foreach ($all_acf_fields as $acf_field_name) {
                     $acf_field_value = get_field($acf_field_name, $post_id);
                     if ($acf_field_value) {
                         $acf_fields[$acf_field_name] = $acf_field_value;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $send_product = array('product_id' => $product->id, 'currency' => get_woocommerce_currency(), 'price' => $product->get_price(), 'url' => get_permalink($product->id), 'thumbnail_url' => $thumbnail, 'action' => 'insert', 'description' => $product->get_post_data()->post_content, 'short_description' => $product->get_post_data()->post_excerpt, 'name' => $product->get_title(), 'sku' => $product->get_sku(), 'categories' => $product->get_categories(), 'tag' => $product_tags, 'store_id' => get_current_blog_id(), 'identifier' => (string) $product->id, 'product_brand' => $product_brands, 'taxonomies' => $taxonomies, 'acf_fields' => $acf_fields, 'sellable' => $product->is_purchasable(), 'visibility' => $product->is_visible(), 'stock_quantity' => $product->get_stock_quantity(), 'is_managing_stock' => $product->managing_stock(), 'is_backorders_allowed' => $product->backorders_allowed(), 'is_purchasable' => $product->is_purchasable(), 'is_in_stock' => $product->is_in_stock(), 'product_status' => get_post_status($post_id));
     try {
         $variable = new WC_Product_Variable($post_id);
//.........这里部分代码省略.........
开发者ID:booklein,项目名称:wpbookle,代码行数:101,代码来源:wcis_plugin.php

示例9: strtotime

 if (!empty($ticket->end_date)) {
     $end_date = strtotime($ticket->end_date . $gmt_offset);
 } else {
     $end_date = strtotime(tribe_get_end_date(get_the_ID(), false, 'Y-m-d G:i') . $gmt_offset);
 }
 $start_date = null;
 if (!empty($ticket->start_date)) {
     $start_date = strtotime($ticket->start_date . $gmt_offset);
 }
 if ((empty($start_date) || time() > $start_date) && (empty($end_date) || time() < $end_date)) {
     $is_there_any_product = true;
     echo sprintf("<input type='hidden' name='product_id[]' value='%d'>", $ticket->ID);
     echo "<tr>";
     echo "<td class='woocommerce'>";
     if ($product->is_in_stock()) {
         woocommerce_quantity_input(array('input_name' => 'quantity_' . $ticket->ID, 'input_value' => 0, 'min_value' => 0, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity()));
         $is_there_any_product_to_sell = true;
     } else {
         echo "<span class='tickets_nostock'>" . esc_html__('Out of stock!', 'tribe-wootickets') . "</span>";
     }
     echo "</td>";
     echo "<td nowrap='nowrap' class='tickets_name'>";
     echo $ticket->name;
     echo "</td>";
     echo "<td class='tickets_price'>";
     echo $this->get_price_html($product);
     echo "</td>";
     echo "<td class='tickets_description'>";
     echo $ticket->description;
     echo "</td>";
     echo "</tr>";
开发者ID:bennet-iwd,项目名称:gamblers-night,代码行数:31,代码来源:tickets.php

示例10: get_product_data

 /**
  * Get standard product data that applies to every product type
  *
  * @since 2.1
  * @param WC_Product $product
  * @return WC_Product
  */
 private function get_product_data($product, $fields = null)
 {
     if ($fields) {
         $field_list = explode(',', $fields);
     }
     $product_data = array();
     if (!$fields || $fields && in_array('title', $field_list)) {
         $product_data['title'] = $product->get_title();
     }
     if (!$fields || $fields && in_array('id', $field_list)) {
         $product_data['id'] = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id;
     }
     if (!$fields || $fields && in_array('created_at', $field_list)) {
         $product_data['created_at'] = $this->server->format_datetime($product->get_post_data()->post_date_gmt);
     }
     if (!$fields || $fields && in_array('updated_at', $field_list)) {
         $product_data['updated_at'] = $this->server->format_datetime($product->get_post_data()->post_modified_gmt);
     }
     if (!$fields || $fields && in_array('type', $field_list)) {
         $product_data['type'] = $product->product_type;
     }
     if (!$fields || $fields && in_array('status', $field_list)) {
         $product_data['status'] = $product->get_post_data()->post_status;
     }
     if (!$fields || $fields && in_array('downloadable', $field_list)) {
         $product_data['downloadable'] = $product->is_downloadable();
     }
     if (!$fields || $fields && in_array('virtual', $field_list)) {
         $product_data['virtual'] = $product->is_virtual();
     }
     if (!$fields || $fields && in_array('permalink', $field_list)) {
         $product_data['permalink'] = $product->get_permalink();
     }
     if (!$fields || $fields && in_array('sku', $field_list)) {
         $product_data['sku'] = $product->get_sku();
     }
     if (!$fields || $fields && in_array('price', $field_list)) {
         $product_data['price'] = $product->get_price();
     }
     if (!$fields || $fields && in_array('regular_price', $field_list)) {
         $product_data['regular_price'] = $product->get_regular_price();
     }
     if (!$fields || $fields && in_array('sale_price', $field_list)) {
         $product_data['sale_price'] = $product->get_sale_price() ? $product->get_sale_price() : null;
     }
     if (!$fields || $fields && in_array('price_html', $field_list)) {
         $product_data['price_html'] = $product->get_price_html();
     }
     if (!$fields || $fields && in_array('taxable', $field_list)) {
         $product_data['taxable'] = $product->is_taxable();
     }
     if (!$fields || $fields && in_array('tax_status', $field_list)) {
         $product_data['tax_status'] = $product->get_tax_status();
     }
     if (!$fields || $fields && in_array('tax_class', $field_list)) {
         $product_data['tax_class'] = $product->get_tax_class();
     }
     if (!$fields || $fields && in_array('managing_stock', $field_list)) {
         $product_data['managing_stock'] = $product->managing_stock();
     }
     if (!$fields || $fields && in_array('stock_quantity', $field_list)) {
         $product_data['stock_quantity'] = $product->get_stock_quantity();
     }
     if (!$fields || $fields && in_array('in_stock', $field_list)) {
         $product_data['in_stock'] = $product->is_in_stock();
     }
     if (!$fields || $fields && in_array('backorders_allowed', $field_list)) {
         $product_data['backorders_allowed'] = $product->backorders_allowed();
     }
     if (!$fields || $fields && in_array('backordered', $field_list)) {
         $product_data['backordered'] = $product->is_on_backorder();
     }
     if (!$fields || $fields && in_array('sold_individually', $field_list)) {
         $product_data['sold_individually'] = $product->is_sold_individually();
     }
     if (!$fields || $fields && in_array('purchaseable', $field_list)) {
         $product_data['purchaseable'] = $product->is_purchasable();
     }
     if (!$fields || $fields && in_array('featured', $field_list)) {
         $product_data['featured'] = $product->is_featured();
     }
     if (!$fields || $fields && in_array('visible', $field_list)) {
         $product_data['visible'] = $product->is_visible();
     }
     if (!$fields || $fields && in_array('catalog_visibility', $field_list)) {
         $product_data['catalog_visibility'] = $product->visibility;
     }
     if (!$fields || $fields && in_array('on_sale', $field_list)) {
         $product_data['on_sale'] = $product->is_on_sale();
     }
     if (!$fields || $fields && in_array('product_url', $field_list)) {
         $product_data['product_url'] = $product->is_type('external') ? $product->get_product_url() : '';
     }
//.........这里部分代码省略.........
开发者ID:Nils-Fredrik,项目名称:woocommerce,代码行数:101,代码来源:class-wc-api-products.php


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