• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wc_stock_amount函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wc_stock_amount函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_stock_amount函数的具体用法?PHP wc_stock_amount怎么用?PHP wc_stock_amount使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: do_action

		<?php 
    do_action('woocommerce_before_add_to_cart_button');
    ?>

		<div class="single_variation_wrap" style="display:none;">
			<?php 
    do_action('woocommerce_before_single_variation');
    ?>

			<div class="single_variation"></div>

			<div class="variations_button">

				<?php 
    woocommerce_quantity_input(array('input_value' => isset($_POST['quantity']) ? wc_stock_amount($_POST['quantity']) : 1));
    ?>
				<button type="submit" class="single_add_to_cart_button button alt"><?php 
    echo $product->single_add_to_cart_text();
    ?>
</button>
			</div>

			<input type="hidden" name="add-to-cart" value="<?php 
    echo absint($product->id);
    ?>
" />
			<input type="hidden" name="product_id" value="<?php 
    echo absint($product->id);
    ?>
" />
开发者ID:jaredkc,项目名称:wc-variations-radio-buttons,代码行数:30,代码来源:variable.php


示例2: sf_single_variation_add_to_cart_button

function sf_single_variation_add_to_cart_button()
{
    global $product;
    $loading_text = __('Adding...', 'swiftframework');
    $added_text = __('Item added', 'swiftframework');
    ?>
		<div class="variations_button">
			<?php 
    woocommerce_quantity_input(array('input_value' => isset($_POST['quantity']) ? wc_stock_amount($_POST['quantity']) : 1));
    ?>
			<button type="submit" data-product_id="<?php 
    echo esc_attr($product->id);
    ?>
" data-quantity="1" data-default_text="<?php 
    echo esc_attr($product->single_add_to_cart_text());
    ?>
" data-default_icon="sf-icon-add-to-cart" data-loading_text="<?php 
    echo esc_attr($loading_text);
    ?>
" data-added_text="<?php 
    echo esc_attr($added_text);
    ?>
" class="single_add_to_cart_button button alt"><?php 
    echo apply_filters('sf_add_to_cart_icon', '<i class="sf-icon-add-to-cart"></i>');
    ?>
<span><?php 
    echo esc_attr($product->single_add_to_cart_text());
    ?>
</span></button>
			<input type="hidden" name="add-to-cart" value="<?php 
    echo absint($product->id);
    ?>
" />
			<input type="hidden" name="product_id" value="<?php 
    echo absint($product->id);
    ?>
" />
			<input type="hidden" name="variation_id" class="variation_id" value="" />
			<?php 
    echo sf_wishlist_button();
    ?>
		</div>
		<?php 
}
开发者ID:Infernosaint,项目名称:WPSetupTest2,代码行数:44,代码来源:sf-woocommerce.php


示例3: hwoo_simple_product_quantity_input

 /**
  * @param $product
  */
 function hwoo_simple_product_quantity_input($product)
 {
     if ($product instanceof HWoo_TimberProduct) {
         $product = $product->wc_product();
     }
     if (!$product->is_sold_individually()) {
         woocommerce_quantity_input(array('min_value' => apply_filters('woocommerce_quantity_input_min', 1, $product), 'max_value' => apply_filters('woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product), 'input_value' => isset($_POST['quantity']) ? wc_stock_amount($_POST['quantity']) : 1));
     }
 }
开发者ID:hoangsoft90,项目名称:hw-hoangweb-plugin,代码行数:12,代码来源:template-functions.php


示例4: show_select_qty_btn_single

/**
 * Show input qty on single product
 * @return write
 */
function show_select_qty_btn_single()
{
    global $product;
    $qty = isset($_POST['quantity']) ? wc_stock_amount($_POST['quantity']) : 1;
    if (!$product->is_sold_individually()) {
        echo '<div class="buttons-qty">';
        echo '<span>+</span>';
        echo '<input class="single-product" data-id="' . $product->id . '" type="text" value="' . $qty . '" />';
        echo '<span>-</span>';
        echo '</div>';
    }
}
开发者ID:brasadesign,项目名称:aboaterra-theme,代码行数:16,代码来源:hooks.php


示例5: woocommerce_wp_text_input

/**
 * Output a text input box.
 *
 * @param array $field
 */
function woocommerce_wp_text_input($field)
{
    global $thepostid, $post;
    $thepostid = empty($thepostid) ? $post->ID : $thepostid;
    $field['placeholder'] = isset($field['placeholder']) ? $field['placeholder'] : '';
    $field['class'] = isset($field['class']) ? $field['class'] : 'short';
    $field['style'] = isset($field['style']) ? $field['style'] : '';
    $field['wrapper_class'] = isset($field['wrapper_class']) ? $field['wrapper_class'] : '';
    $field['value'] = isset($field['value']) ? $field['value'] : get_post_meta($thepostid, $field['id'], true);
    $field['name'] = isset($field['name']) ? $field['name'] : $field['id'];
    $field['type'] = isset($field['type']) ? $field['type'] : 'text';
    $field['desc_tip'] = isset($field['desc_tip']) ? $field['desc_tip'] : false;
    $data_type = empty($field['data_type']) ? '' : $field['data_type'];
    switch ($data_type) {
        case 'price':
            $field['class'] .= ' wc_input_price';
            $field['value'] = wc_format_localized_price($field['value']);
            break;
        case 'decimal':
            $field['class'] .= ' wc_input_decimal';
            $field['value'] = wc_format_localized_decimal($field['value']);
            break;
        case 'stock':
            $field['class'] .= ' wc_input_stock';
            $field['value'] = wc_stock_amount($field['value']);
            break;
        case 'url':
            $field['class'] .= ' wc_input_url';
            $field['value'] = esc_url($field['value']);
            break;
        default:
            break;
    }
    // Custom attribute handling
    $custom_attributes = array();
    if (!empty($field['custom_attributes']) && is_array($field['custom_attributes'])) {
        foreach ($field['custom_attributes'] as $attribute => $value) {
            $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($value) . '"';
        }
    }
    echo '<p class="form-field ' . esc_attr($field['id']) . '_field ' . esc_attr($field['wrapper_class']) . '">
		<label for="' . esc_attr($field['id']) . '">' . wp_kses_post($field['label']) . '</label>';
    if (!empty($field['description']) && false !== $field['desc_tip']) {
        echo wc_help_tip($field['description']);
    }
    echo '<input type="' . esc_attr($field['type']) . '" class="' . esc_attr($field['class']) . '" style="' . esc_attr($field['style']) . '" name="' . esc_attr($field['name']) . '" id="' . esc_attr($field['id']) . '" value="' . esc_attr($field['value']) . '" placeholder="' . esc_attr($field['placeholder']) . '" ' . implode(' ', $custom_attributes) . ' /> ';
    if (!empty($field['description']) && false === $field['desc_tip']) {
        echo '<span class="description">' . wp_kses_post($field['description']) . '</span>';
    }
    echo '</p>';
}
开发者ID:woocommerce,项目名称:woocommerce,代码行数:56,代码来源:wc-meta-box-functions.php


示例6: get_total_stock

 /**
  * Get total stock.
  *
  * This is the stock of parent and children combined.
  *
  * @access public
  * @return int
  */
 public function get_total_stock()
 {
     if (empty($this->total_stock)) {
         $transient_name = 'wc_product_total_stock_' . $this->id . WC_Cache_Helper::get_transient_version('product');
         if (false === ($this->total_stock = get_transient($transient_name))) {
             $this->total_stock = max(0, wc_stock_amount($this->stock));
             if (sizeof($this->get_children()) > 0) {
                 foreach ($this->get_children() as $child_id) {
                     if ('yes' === get_post_meta($child_id, '_manage_stock', true)) {
                         $stock = get_post_meta($child_id, '_stock', true);
                         $this->total_stock += max(0, wc_stock_amount($stock));
                     }
                 }
             }
             set_transient($transient_name, $this->total_stock, DAY_IN_SECONDS * 30);
         }
     }
     return wc_stock_amount($this->total_stock);
 }
开发者ID:EstefanoCruz,项目名称:woocommerce,代码行数:27,代码来源:class-wc-product-variable.php


示例7: get_total_stock

 /**
  * Get total stock.
  *
  * This is the stock of parent and children combined.
  *
  * @access public
  * @return int
  */
 public function get_total_stock()
 {
     if (empty($this->total_stock)) {
         $transient_name = 'wc_product_total_stock_' . $this->id;
         if (false === ($this->total_stock = get_transient($transient_name))) {
             $this->total_stock = $this->stock;
             if (sizeof($this->get_children()) > 0) {
                 foreach ($this->get_children() as $child_id) {
                     $stock = get_post_meta($child_id, '_stock', true);
                     if ($stock != '') {
                         $this->total_stock += wc_stock_amount($stock);
                     }
                 }
             }
             set_transient($transient_name, $this->total_stock, YEAR_IN_SECONDS);
         }
     }
     return wc_stock_amount($this->total_stock);
 }
开发者ID:anagio,项目名称:woocommerce,代码行数:27,代码来源:class-wc-product-grouped.php


示例8: get_items

 /**
  * Get sales reports.
  *
  * @param WP_REST_Request $request
  * @return array|WP_Error
  */
 public function get_items($request)
 {
     // Set date filtering.
     $filter = array('period' => $request['period'], 'date_min' => $request['date_min'], 'date_max' => $request['date_max']);
     $this->setup_report($filter);
     $report_data = $this->report->get_order_report_data(array('data' => array('_product_id' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => '', 'name' => 'product_id'), '_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_qty')), 'order_by' => 'order_item_qty DESC', 'group_by' => 'product_id', 'limit' => isset($filter['limit']) ? absint($filter['limit']) : 12, 'query_type' => 'get_results', 'filter_range' => true));
     $top_sellers = array();
     foreach ($report_data as $item) {
         $product = wc_get_product($item->product_id);
         if ($product) {
             $top_sellers[] = array('name' => $product->get_title(), 'product_id' => (int) $item->product_id, 'quantity' => wc_stock_amount($item->order_item_qty));
         }
     }
     $data = array();
     foreach ($top_sellers as $top_seller) {
         $item = $this->prepare_item_for_response((object) $top_seller, $request);
         $data[] = $this->prepare_response_for_collection($item);
     }
     return rest_ensure_response($data);
 }
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:26,代码来源:class-wc-rest-report-top-sellers-controller.php


示例9: woocommerce_single_variation_add_to_cart_button

/**
 * Override the Output the add to cart button for variations.
 */
function woocommerce_single_variation_add_to_cart_button()
{
    global $product;
    ?>
    <div class="variations_button">
        <button type="submit" class="single_add_to_cart_button button alt"><?php 
    echo esc_html($product->single_add_to_cart_text());
    ?>
</button>
        <input type="hidden" name="add-to-cart" value="<?php 
    echo absint($product->id);
    ?>
" />
        <input type="hidden" name="product_id" value="<?php 
    echo absint($product->id);
    ?>
" />
        <input type="hidden" name="variation_id" class="variation_id" value="" />
        <?php 
    woocommerce_quantity_input(array('input_value' => isset($_POST['quantity']) ? wc_stock_amount($_POST['quantity']) : 1));
    ?>
    </div>
    <?php 
}
开发者ID:bqevin,项目名称:wp-shopeasy,代码行数:27,代码来源:template-tags-categories.php


示例10: save_variations_data

 /**
  * Save variations.
  *
  * @throws WC_REST_Exception REST API exceptions.
  * @param WC_Product      $product          Product instance.
  * @param WP_REST_Request $request          Request data.
  * @param bool            $single_variation True if saving only a single variation.
  * @return bool
  */
 protected function save_variations_data($product, $request, $single_variation = false)
 {
     global $wpdb;
     if ($single_variation) {
         $variations = array($request);
     } else {
         $variations = $request['variations'];
     }
     foreach ($variations as $menu_order => $data) {
         $variation_id = isset($data['id']) ? absint($data['id']) : 0;
         $variation = new WC_Product_Variation($variation_id);
         // Create initial name and status.
         if (!$variation->get_slug()) {
             /* translators: 1: variation id 2: product name */
             $variation->set_name(sprintf(__('Variation #%1$s of %2$s', 'woocommerce'), $variation->get_id(), $product->get_name()));
             $variation->set_status(isset($data['visible']) && false === $data['visible'] ? 'private' : 'publish');
         }
         // Parent ID.
         $variation->set_parent_id($product->get_id());
         // Menu order.
         $variation->set_menu_order($menu_order);
         // Status.
         if (isset($data['visible'])) {
             $variation->set_status(false === $data['visible'] ? 'private' : 'publish');
         }
         // SKU.
         if (isset($data['sku'])) {
             $variation->set_sku(wc_clean($data['sku']));
         }
         // Thumbnail.
         if (isset($data['image']) && is_array($data['image'])) {
             $image = $data['image'];
             $image = current($image);
             if (is_array($image)) {
                 $image['position'] = 0;
             }
             $variation = $this->save_product_images($variation, array($image));
         }
         // Virtual variation.
         if (isset($data['virtual'])) {
             $variation->set_virtual($data['virtual']);
         }
         // Downloadable variation.
         if (isset($data['downloadable'])) {
             $variation->set_downloadable($data['downloadable']);
         }
         // Downloads.
         if ($variation->get_downloadable()) {
             // Downloadable files.
             if (isset($data['downloads']) && is_array($data['downloads'])) {
                 $variation = $this->save_downloadable_files($variation, $data['downloads']);
             }
             // Download limit.
             if (isset($data['download_limit'])) {
                 $variation->set_download_limit($data['download_limit']);
             }
             // Download expiry.
             if (isset($data['download_expiry'])) {
                 $variation->set_download_expiry($data['download_expiry']);
             }
         }
         // Shipping data.
         $variation = $this->save_product_shipping_data($variation, $data);
         // Stock handling.
         if (isset($data['manage_stock'])) {
             $variation->set_manage_stock($data['manage_stock']);
         }
         if (isset($data['in_stock'])) {
             $variation->set_stock_status(true === $data['in_stock'] ? 'instock' : 'outofstock');
         }
         if (isset($data['backorders'])) {
             $variation->set_backorders($data['backorders']);
         }
         if ($variation->get_manage_stock()) {
             if (isset($data['stock_quantity'])) {
                 $variation->set_stock_quantity($data['stock_quantity']);
             } elseif (isset($data['inventory_delta'])) {
                 $stock_quantity = wc_stock_amount($variation->get_stock_amount());
                 $stock_quantity += wc_stock_amount($data['inventory_delta']);
                 $variation->set_stock_quantity($stock_quantity);
             }
         } else {
             $variation->set_backorders('no');
             $variation->set_stock_quantity('');
         }
         // Regular Price.
         if (isset($data['regular_price'])) {
             $variation->set_regular_price($data['regular_price']);
         }
         // Sale Price.
         if (isset($data['sale_price'])) {
//.........这里部分代码省略.........
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:101,代码来源:class-wc-rest-products-controller.php


示例11: save_variations


//.........这里部分代码省略.........
                     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) {
                 update_post_meta($variation_id, '_backorders', wc_clean($variable_backorders[$i]));
                 wc_update_product_stock($variation_id, wc_stock_amount($variable_stock[$i]));
             } else {
                 delete_post_meta($variation_id, '_backorders');
                 delete_post_meta($variation_id, '_stock');
             }
             // Price handling
             $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);
             // Save Dates
             update_post_meta($variation_id, '_sale_price_dates_from', $date_from ? strtotime($date_from) : '');
             update_post_meta($variation_id, '_sale_price_dates_to', $date_to ? strtotime($date_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);
             }
             if ('' !== $sale_price && $date_from && strtotime($date_from) < strtotime('NOW', current_time('timestamp'))) {
                 update_post_meta($variation_id, '_price', $sale_price);
             }
             if ($date_to && strtotime($date_to) < strtotime('NOW', current_time('timestamp'))) {
                 update_post_meta($variation_id, '_price', $regular_price);
                 update_post_meta($variation_id, '_sale_price_dates_from', '');
                 update_post_meta($variation_id, '_sale_price_dates_to', '');
             }
             if (isset($variable_tax_class[$i]) && $variable_tax_class[$i] !== 'parent') {
开发者ID:WordCommerce,项目名称:woocommerce,代码行数:67,代码来源:class-wc-meta-box-product-data.php


示例12: prepare_item_for_response

 /**
  * Prepare a single order output for response.
  *
  * @param WP_Post $post Post object.
  * @param WP_REST_Request $request Request object.
  * @return WP_REST_Response $data
  */
 public function prepare_item_for_response($post, $request)
 {
     global $wpdb;
     $order = wc_get_order($post);
     $dp = $request['dp'];
     $data = array('id' => $order->id, 'parent_id' => $post->post_parent, 'status' => $order->get_status(), 'order_key' => $order->order_key, 'currency' => $order->get_order_currency(), 'version' => $order->order_version, 'prices_include_tax' => $order->prices_include_tax, 'date_created' => wc_rest_prepare_date_response($post->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($post->post_modified_gmt), 'customer_id' => $order->get_user_id(), 'discount_total' => wc_format_decimal($order->get_total_discount(), $dp), 'discount_tax' => wc_format_decimal($order->cart_discount_tax, $dp), 'shipping_total' => wc_format_decimal($order->get_total_shipping(), $dp), 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), 'total' => wc_format_decimal($order->get_total(), $dp), 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), 'billing' => array(), 'shipping' => array(), 'payment_method' => $order->payment_method, 'payment_method_title' => $order->payment_method_title, 'transaction_id' => $order->get_transaction_id(), 'customer_ip_address' => $order->customer_ip_address, 'customer_user_agent' => $order->customer_user_agent, 'created_via' => $order->created_via, 'customer_note' => $order->customer_note, 'date_completed' => wc_rest_prepare_date_response($order->completed_date), 'date_paid' => $order->paid_date, 'cart_hash' => $order->cart_hash, 'line_items' => array(), 'tax_lines' => array(), 'shipping_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array(), 'refunds' => array());
     // Add addresses.
     $data['billing'] = $order->get_address('billing');
     $data['shipping'] = $order->get_address('shipping');
     // Add line items.
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         $product_id = 0;
         $variation_id = 0;
         $product_sku = null;
         // Check if the product exists.
         if (is_object($product)) {
             $product_id = $product->id;
             $variation_id = $product->variation_id;
             $product_sku = $product->get_sku();
         }
         $meta = new WC_Order_Item_Meta($item, $product);
         $item_meta = array();
         $hideprefix = 'true' === $request['all_item_meta'] ? null : '_';
         foreach ($meta->get_formatted($hideprefix) as $meta_key => $formatted_meta) {
             $item_meta[] = array('key' => $formatted_meta['key'], 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
         }
         $line_item = array('id' => $item_id, 'name' => $item['name'], 'sku' => $product_sku, 'product_id' => (int) $product_id, 'variation_id' => (int) $variation_id, 'quantity' => wc_stock_amount($item['qty']), 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : '', 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), 'total_tax' => wc_format_decimal($item['line_tax'], $dp), 'taxes' => array(), 'meta' => $item_meta);
         $item_line_taxes = maybe_unserialize($item['line_tax_data']);
         if (isset($item_line_taxes['total'])) {
             $line_tax = array();
             foreach ($item_line_taxes['total'] as $tax_rate_id => $tax) {
                 $line_tax[$tax_rate_id] = array('id' => $tax_rate_id, 'total' => $tax, 'subtotal' => '');
             }
             foreach ($item_line_taxes['subtotal'] as $tax_rate_id => $tax) {
                 $line_tax[$tax_rate_id]['subtotal'] = $tax;
             }
             $line_item['taxes'] = array_values($line_tax);
         }
         $data['line_items'][] = $line_item;
     }
     // Add taxes.
     foreach ($order->get_items('tax') as $key => $tax) {
         $tax_line = array('id' => $key, 'rate_code' => $tax['name'], 'rate_id' => $tax['rate_id'], 'label' => isset($tax['label']) ? $tax['label'] : $tax['name'], 'compound' => (bool) $tax['compound'], 'tax_total' => wc_format_decimal($tax['tax_amount'], $dp), 'shipping_tax_total' => wc_format_decimal($tax['shipping_tax_amount'], $dp));
         $data['tax_lines'][] = $tax_line;
     }
     // Add shipping.
     foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
         $shipping_line = array('id' => $shipping_item_id, 'method_title' => $shipping_item['name'], 'method_id' => $shipping_item['method_id'], 'total' => wc_format_decimal($shipping_item['cost'], $dp), 'total_tax' => wc_format_decimal('', $dp), 'taxes' => array());
         $shipping_taxes = maybe_unserialize($shipping_item['taxes']);
         if (!empty($shipping_taxes)) {
             $shipping_line['total_tax'] = wc_format_decimal(array_sum($shipping_taxes), $dp);
             foreach ($shipping_taxes as $tax_rate_id => $tax) {
                 $shipping_line['taxes'][] = array('id' => $tax_rate_id, 'total' => $tax);
             }
         }
         $data['shipping_lines'][] = $shipping_line;
     }
     // Add fees.
     foreach ($order->get_fees() as $fee_item_id => $fee_item) {
         $fee_line = array('id' => $fee_item_id, 'name' => $fee_item['name'], 'tax_class' => !empty($fee_item['tax_class']) ? $fee_item['tax_class'] : '', 'tax_status' => 'taxable', 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp), 'taxes' => array());
         $fee_line_taxes = maybe_unserialize($fee_item['line_tax_data']);
         if (isset($fee_line_taxes['total'])) {
             $fee_tax = array();
             foreach ($fee_line_taxes['total'] as $tax_rate_id => $tax) {
                 $fee_tax[$tax_rate_id] = array('id' => $tax_rate_id, 'total' => $tax, 'subtotal' => '');
             }
             foreach ($fee_line_taxes['subtotal'] as $tax_rate_id => $tax) {
                 $fee_tax[$tax_rate_id]['subtotal'] = $tax;
             }
             $fee_line['taxes'] = array_values($fee_tax);
         }
         $data['fee_lines'][] = $fee_line;
     }
     // Add coupons.
     foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
         $coupon_line = array('id' => $coupon_item_id, 'code' => $coupon_item['name'], 'discount' => wc_format_decimal($coupon_item['discount_amount'], $dp), 'discount_tax' => wc_format_decimal($coupon_item['discount_amount_tax'], $dp));
         $data['coupon_lines'][] = $coupon_line;
     }
     // Add refunds.
     foreach ($order->get_refunds() as $refund) {
         $data['refunds'][] = array('id' => $refund->id, 'refund' => $refund->get_refund_reason() ? $refund->get_refund_reason() : '', 'total' => '-' . wc_format_decimal($refund->get_refund_amount(), $dp));
     }
     $context = !empty($request['context']) ? $request['context'] : 'view';
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     // Wrap the data in a response object.
     $response = rest_ensure_response($data);
     $response->add_links($this->prepare_links($order));
     /**
      * Filter the data for a response.
      *
      * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
//.........这里部分代码省略.........
开发者ID:coderkevin,项目名称:woocommerce,代码行数:101,代码来源:class-wc-rest-orders-controller.php


示例13: do_action

<?php 
if ($product->is_in_stock()) {
    ?>

	<?php 
    do_action('woocommerce_before_add_to_cart_form');
    ?>

	<form class="cart" method="post" enctype='multipart/form-data'>
	 	<?php 
    do_action('woocommerce_before_add_to_cart_button');
    ?>

	 	<?php 
    if (!$product->is_sold_individually()) {
        woocommerce_quantity_input(array('min_value' => apply_filters('woocommerce_quantity_input_min', 1, $product), 'max_value' => apply_filters('woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product), 'input_value' => isset($_POST['quantity']) ? wc_stock_amount($_POST['quantity']) : 1));
    }
    ?>

	 	<input type="hidden" name="add-to-cart" value="<?php 
    echo esc_attr($product->id);
    ?>
" />

	 	<button type="submit" class="single_add_to_cart_button button alt"><?php 
    echo esc_html($product->single_add_to_cart_text());
    ?>
</button>

		<?php 
    do_action('woocommerce_after_add_to_cart_button');
开发者ID:booklein,项目名称:wpbookle,代码行数:31,代码来源:simple.php


示例14: get_stock_quantity

 /**
  * Returns number of items available for sale.
  *
  * @return int
  */
 public function get_stock_quantity()
 {
     return apply_filters('woocommerce_get_stock_quantity', $this->managing_stock() ? wc_stock_amount($this->stock) : '', $this);
 }
开发者ID:randyriolis,项目名称:woocommerce,代码行数:9,代码来源:abstract-wc-product.php


示例15: variation_bulk_action_variable_stock

 /**
  * Bulk action - Set Stock
  * @access private
  * @param  array $variations
  * @param  array $data
  */
 private static function variation_bulk_action_variable_stock($variations, $data)
 {
     if (empty($data['value'])) {
         break;
     }
     $value = wc_clean($data['value']);
     if ($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');
             }
         }
     }
 }
开发者ID:JodiWarren,项目名称:woocommerce,代码行数:22,代码来源:class-wc-ajax.php


示例16: setup_postdata

    setup_postdata($post);
    ?>
          <tr>
            <td>
              <?php 
    if ($product->is_sold_individually() || !$product->is_purchasable()) {
        ?>
                <?php 
        woocommerce_template_loop_add_to_cart();
        ?>
              <?php 
    } else {
        ?>
                <?php 
        $quantites_required = true;
        woocommerce_quantity_input(array('input_name' => 'quantity[' . $product_id . ']', 'input_value' => isset($_POST['quantity'][$product_id]) ? wc_stock_amount($_POST['quantity'][$product_id]) : 0, 'min_value' => apply_filters('woocommerce_quantity_input_min', 0, $product), 'max_value' => apply_filters('woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product)));
        ?>
              <?php 
    }
    ?>
            </td>

            <td class="label">
              <label for="product-<?php 
    echo $product_id;
    ?>
">
                <?php 
    echo $product->is_visible() ? '<a href="' . esc_url(apply_filters('woocommerce_grouped_product_list_link', get_permalink(), $product_id)) . '">' . esc_html(get_the_title()) . '</a>' : esc_html(get_the_title());
    ?>
              </label>
开发者ID:crazyyy,项目名称:smartmagel,代码行数:31,代码来源:grouped.php


示例17: save_variations


//.........这里部分代码省略.........
         // 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['managing_stock'])) {
             $managing_stock = true === $variation['managing_stock'] ? 'yes' : 'no';
             update_post_meta($variation_id, '_manage_stock', $managing_stock);
         } else {
             $managing_stock = get_post_meta($variation_id, '_manage_stock', true);
         }
         // 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($variation['in_stock'])) {
             $stock_status = true === $variation['in_stock'] ? 'instock' : 'outofstock';
             wc_update_product_stock_status($variation_id, $stock_status);
         }
         if ('yes' === $managing_stock) {
             if (isset($variation['backorders'])) {
                 if ('notify' == $variation['backorders']) {
                     $backorders = 'notify';
                 } else {
                     $backorders = true === $variation['backorders'] ? 'yes' : 'no';
                 }
             } else {
                 $backorders = 'no';
             }
             update_post_meta($variation_id, '_backorders', $backorders);
             if (isset($variation['stock_quantity'])) {
                 wc_update_product_stock($variation_id, wc_stock_amount($variation['stock_quantity']));
             } else {
                 if (isset($data['inventory_delta'])) {
                     $stock_quantity = wc_stock_amount(get_post_meta($variation_id, '_stock', true));
                     $stock_quantity += wc_stock_amount($data['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'] ? '' : wc_format_decimal($variation['regular_price']);
             update_post_meta($variation_id, '_regular_price', $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'] ? '' : wc_format_decimal($variation['sale_price']);
             update_post_meta($variation_id, '_sale_price', $sale_price);
         } else {
             $sale_price = get_post_meta($variation_id, '_sale_price', true);
         }
         $date_from = isset($variation['sale_price_dates_from']) ? strtotime($variation['sale_price_dates_from']) : get_post_meta($variation_id, '_sale_price_dates_from', true);
         $date_to = isset($variation['sale_price_dates_to']) ? strtotime($variation['sale_price_dates_to']) : get_post_meta($variation_id, '_sale_price_dates_to', true);
         // Save Dates
         if ($date_from) {
             update_post_meta($variation_id, '_sale_price_dates_from', $date_from);
         } else {
             update_post_meta($variation_id, '_sale_price_dates_from', '');
开发者ID:haltaction,项目名称:woocommerce,代码行数:67,代码来源:class-wc-api-products.php


示例18: update_product

 /**
  * Update a line item for the order
  *
  * Note this does not update order totals
  *
  * @since 2.2
  * @param int $item_id order item ID
  * @param array $args data to update
  * @param WC_Product $product
  * @return bool
  */
 public function update_product($item_id, $product, $args)
 {
     if (!$item_id || !is_object($product)) {
         return false;
     }
     // quantity
     if (isset($args['qty'])) {
         wc_update_order_item_meta($item_id, '_qty', wc_stock_amount($args['qty']));
     }
     // tax class
     if (isset($args['tax_class'])) {
         wc_update_order_item_meta($item_id, '_tax_class', $args['tax_class']);
     }
     // set item totals, either provided or from product
     if (isset($args['qty'])) {
         wc_update_order_item_meta($item_id, '_line_subtotal', wc_format_decimal(isset($args['totals']['subtotal']) ? $args['totals']['subtotal'] : $product->get_price_excluding_tax($args['qty'])));
         wc_update_order_item_meta($item_id, '_line_total', wc_format_decimal(isset($args['totals']['total']) ? $args['totals']['total'] : $product->get_price_excluding_tax($args['qty'])));
     }
     // set item tax totals
     wc_update_order_item_meta($item_id, '_line_subtotal_tax', wc_format_decimal(isset($args['totals']['subtotal_tax']) ? $args['totals']['subtotal_tax'] : 0));
     wc_update_order_item_meta($item_id, '_line_tax', wc_format_decimal(isset($args['totals']['tax']) ? $args['totals']['tax'] : 0));
     // variation meta
     if (isset($args['variation']) && is_array($args['variation'])) {
         foreach ($args['variation'] as $key => $value) {
             wc_update_order_item_meta($item_id, str_replace('attribute_', '', $key), $value);
         }
     }
     // backorders
     if (isset($args['qty']) && $product->backorders_require_notification() && $product->is_on_backorder($args['qty'])) {
         wc_update_order_item_meta($item_id, apply_filters('woocommerce_backordered_item_meta_name', __('Backordered', 'woocommerce')), $args['qty'] - max(0, $product->get_total_stock()));
     }
     do_action('woocommerce_order_edit_product', $this->id, $item_id, $args, $product);
     return true;
 }
开发者ID:danisdead,项目名称:gastrointernacional,代码行数:45,代码来源:abstract-wc-order.php


示例19: get_order_data


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wc_tax_enabled函数代码示例发布时间:2022-05-23
下一篇:
PHP wc_site_is_https函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap