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


PHP WC_Product::get_tax_class方法代码示例

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


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

 /**
  * Add a product line item to the order
  *
  * @since 2.2
  * @param \WC_Product $product
  * @param int $qty Line item quantity
  * @param array $args
  * @return int|bool Item ID or false
  */
 public function add_product($product, $qty = 1, $args = array())
 {
     $default_args = array('variation' => array(), 'totals' => array());
     $args = wp_parse_args($args, $default_args);
     $item_id = wc_add_order_item($this->id, array('order_item_name' => $product->get_title(), 'order_item_type' => 'line_item'));
     if (!$item_id) {
         return false;
     }
     wc_add_order_item_meta($item_id, '_qty', wc_stock_amount($qty));
     wc_add_order_item_meta($item_id, '_tax_class', $product->get_tax_class());
     wc_add_order_item_meta($item_id, '_product_id', $product->id);
     wc_add_order_item_meta($item_id, '_variation_id', isset($product->variation_id) ? $product->variation_id : 0);
     // Set line item totals, either passed in or from the product
     wc_add_order_item_meta($item_id, '_line_subtotal', wc_format_decimal(isset($args['totals']['subtotal']) ? $args['totals']['subtotal'] : $product->get_price_excluding_tax($qty)));
     wc_add_order_item_meta($item_id, '_line_total', wc_format_decimal(isset($args['totals']['total']) ? $args['totals']['total'] : $product->get_price_excluding_tax($qty)));
     wc_add_order_item_meta($item_id, '_line_subtotal_tax', wc_format_decimal(isset($args['totals']['subtotal_tax']) ? $args['totals']['subtotal_tax'] : 0));
     wc_add_order_item_meta($item_id, '_line_tax', wc_format_decimal(isset($args['totals']['tax']) ? $args['totals']['tax'] : 0));
     // Save tax data - Since 2.2
     if (isset($args['totals']['tax_data'])) {
         $tax_data = array();
         $tax_data['total'] = array_map('wc_format_decimal', $args['totals']['tax_data']['total']);
         $tax_data['subtotal'] = array_map('wc_format_decimal', $args['totals']['tax_data']['subtotal']);
         wc_add_order_item_meta($item_id, '_line_tax_data', $tax_data);
     } else {
         wc_add_order_item_meta($item_id, '_line_tax_data', array('total' => array(), 'subtotal' => array()));
     }
     // Add variation meta
     if (!empty($args['variation'])) {
         foreach ($args['variation'] as $key => $value) {
             wc_add_order_item_meta($item_id, str_replace('attribute_', '', $key), $value);
         }
     }
     // Backorders
     if ($product->backorders_require_notification() && $product->is_on_backorder($qty)) {
         wc_add_order_item_meta($item_id, apply_filters('woocommerce_backordered_item_meta_name', __('Backordered', 'woocommerce')), $qty - max(0, $product->get_total_stock()));
     }
     do_action('woocommerce_order_add_product', $this->id, $item_id, $product, $qty, $args);
     return $item_id;
 }
开发者ID:danisdead,项目名称:gastrointernacional,代码行数:48,代码来源:abstract-wc-order.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: add_product

 /**
  * Add a product line item to the order. This is the only line item type with
  * it's own method because it saves looking up order amounts (costs are added up for you).
  * @param  \WC_Product $product
  * @param  int $qty
  * @param  array $args
  * @return int order item ID
  * @throws WC_Data_Exception
  */
 public function add_product($product, $qty = 1, $args = array())
 {
     if ($product) {
         $default_args = array('name' => $product->get_title(), 'tax_class' => $product->get_tax_class(), 'product_id' => $product->get_id(), 'variation_id' => isset($product->variation_id) ? $product->variation_id : 0, 'variation' => isset($product->variation_id) ? $product->get_variation_attributes() : array(), 'subtotal' => $product->get_price_excluding_tax($qty), 'total' => $product->get_price_excluding_tax($qty), 'quantity' => $qty);
     } else {
         $default_args = array('quantity' => $qty);
     }
     $args = wp_parse_args($args, $default_args);
     // BW compatibility with old args
     if (isset($args['totals'])) {
         foreach ($args['totals'] as $key => $value) {
             if ('tax' === $key) {
                 $args['total_tax'] = $value;
             } elseif ('tax_data' === $key) {
                 $args['taxes'] = $value;
             } else {
                 $args[$key] = $value;
             }
         }
     }
     $item = new WC_Order_Item_Product($args);
     $item->set_backorder_meta();
     $item->set_order_id($this->get_id());
     $item->save();
     $this->add_item($item);
     wc_do_deprecated_action('woocommerce_order_add_product', array($this->get_id(), $item->get_id(), $product, $qty, $args), '2.7', 'Use woocommerce_new_order_item action instead.');
     return $item->get_id();
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:37,代码来源:abstract-wc-order.php

示例5: calculate_tax_for_subscription

 /**
  * Calculates a price (could be per period price or sign-up fee) for a subscription less tax
  * if the subscription is taxable and the prices in the store include tax.
  *
  * Based on the WC_Product::get_price_excluding_tax() function.
  *
  * @param float $price The price to adjust based on taxes
  * @param WC_Product $product The product the price belongs too (needed to determine tax class)
  * @since 1.0
  */
 public static function calculate_tax_for_subscription($price, $product, $deduct_base_taxes = false)
 {
     _deprecated_function(__METHOD__, '1.5.8', 'WC_Product::get_price_including_tax()');
     if ($product->is_taxable()) {
         $tax = new WC_Tax();
         $base_tax_rates = $tax->get_shop_base_rate($product->tax_class);
         $tax_rates = $tax->get_rates($product->get_tax_class());
         // This will get the base rate unless we're on the checkout page
         if ($deduct_base_taxes && get_option('woocommerce_prices_include_tax') == 'yes') {
             $base_taxes = $tax->calc_tax($price, $base_tax_rates, true);
             $taxes = $tax->calc_tax($price - array_sum($base_taxes), $tax_rates, false);
         } elseif (get_option('woocommerce_prices_include_tax') == 'yes') {
             $taxes = $tax->calc_tax($price, $base_tax_rates, true);
         } else {
             $taxes = $tax->calc_tax($price, $base_tax_rates, false);
         }
         $tax_amount = $tax->get_tax_total($taxes);
     } else {
         $tax_amount = 0;
     }
     return $tax_amount;
 }
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:32,代码来源:class-wc-subscriptions-product.php

示例6: wc_get_price_excluding_tax

/**
 * For a given product, and optionally price/qty, work out the price with tax excluded, based on store settings.
 * @since  2.7.0
 * @param  WC_Product $product
 * @param  array $args
 * @return float
 */
function wc_get_price_excluding_tax($product, $args = array())
{
    $args = wp_parse_args($args, array('qty' => '', 'price' => ''));
    $price = $args['price'] ? $args['price'] : $product->get_price();
    $qty = $args['qty'] ? $args['qty'] : 1;
    if ($product->is_taxable() && wc_prices_include_tax()) {
        $tax_rates = WC_Tax::get_base_tax_rates($product->get_tax_class(true));
        $taxes = WC_Tax::calc_tax($price * $qty, $tax_rates, true);
        $price = WC_Tax::round($price * $qty - array_sum($taxes));
    } else {
        $price = $price * $qty;
    }
    return apply_filters('woocommerce_get_price_excluding_tax', $price, $qty, $product);
}
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:21,代码来源:wc-product-functions.php

示例7: get_formatted_taxes

 /**
  * Displays each cart tax in a subscription string and calculates the sign-up fee taxes (if any)
  * to display in the string.
  *
  * @since 1.0
  */
 public static function get_formatted_taxes($taxes)
 {
     global $woocommerce;
     if (self::cart_contains_subscription()) {
         foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
             $product = new WC_Product($cart_item['product_id']);
             if ($product->is_taxable()) {
                 $base_tax_rates = $woocommerce->cart->tax->get_shop_base_rate($product->tax_class);
                 $tax_rates = $woocommerce->cart->tax->get_rates($product->get_tax_class());
                 // This will get the base rate unless we're on the checkout page
                 $signup_fee = WC_Subscriptions_Product::get_sign_up_fee($product);
                 // Remove discounts from sign-up fee
                 if ($woocommerce->cart->sign_up_fee_discount_cart) {
                     $signup_fee -= $woocommerce->cart->sign_up_fee_discount_cart;
                 }
                 if ($woocommerce->cart->display_cart_ex_tax && $tax_rates == $base_tax_rates && $woocommerce->cart->prices_include_tax) {
                     if ($signup_fee > 0) {
                         $signup_taxes = $woocommerce->cart->tax->calc_tax($signup_fee, $base_tax_rates, true);
                     }
                 } elseif ($woocommerce->cart->display_cart_ex_tax && $woocommerce->cart->prices_include_tax) {
                     if ($signup_fee > 0) {
                         $base_signup_taxes = $woocommerce->cart->tax->calc_tax($signup_fee, $base_tax_rates, true, true);
                         $signup_taxes = $woocommerce->cart->tax->calc_tax($signup_fee - array_sum($base_signup_taxes), $tax_rates, false);
                     }
                 } else {
                     if ($signup_fee > 0) {
                         $signup_taxes = $woocommerce->cart->tax->calc_tax($signup_fee, $tax_rates, false);
                     }
                 }
             }
             foreach ($taxes as $tax_id => $tax_amount) {
                 $subscription_interval = WC_Subscriptions_Product::get_interval($product);
                 $subscription_tax_string = sprintf(_n(' %s / %s', ' %s every %s', $subscription_interval, WC_Subscriptions::$text_domain), $tax_amount, WC_Subscriptions_Manager::get_subscription_period_strings($subscription_interval, WC_Subscriptions_Product::get_period($product)));
                 if (WC_Subscriptions_Product::get_sign_up_fee($product) && isset($signup_taxes[$tax_id]) && $signup_taxes[$tax_id] > 0) {
                     $subscription_tax_string = sprintf(__('%s with %s tax on the sign-up fee', WC_Subscriptions::$text_domain), $subscription_tax_string, woocommerce_price($signup_taxes[$tax_id]));
                 }
                 $taxes[$tax_id] = $subscription_tax_string;
             }
         }
     }
     return $taxes;
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:48,代码来源:class-wc-subscriptions-cart.php

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