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


PHP WC_Tax::calc_tax方法代码示例

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


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

示例1: calculate_fees

 /**
  * Calculate fees
  */
 public function calculate_fees()
 {
     // Reset fees before calculation
     $this->fee_total = 0;
     $this->fees = array();
     // Fire an action where developers can add their fees
     do_action('woocommerce_cart_calculate_fees', $this);
     // If fees were added, total them and calculate tax
     if (!empty($this->fees)) {
         foreach ($this->fees as $fee_key => $fee) {
             $this->fee_total += $fee->amount;
             if ($fee->taxable) {
                 // Get tax rates
                 $tax_rates = $this->tax->get_rates($fee->tax_class);
                 $fee_taxes = $this->tax->calc_tax($fee->amount, $tax_rates, false);
                 if (!empty($fee_taxes)) {
                     // Set the tax total for this fee
                     $this->fees[$fee_key]->tax = array_sum($fee_taxes);
                     // Set tax data - Since 2.2
                     $this->fees[$fee_key]->tax_data = $fee_taxes;
                     // Tax rows - merge the totals we just got
                     foreach (array_keys($this->taxes + $fee_taxes) as $key) {
                         $this->taxes[$key] = (isset($fee_taxes[$key]) ? $fee_taxes[$key] : 0) + (isset($this->taxes[$key]) ? $this->taxes[$key] : 0);
                     }
                 }
             }
         }
     }
 }
开发者ID:joshquila,项目名称:demo2-youse,代码行数:32,代码来源:class-wc-cart.php

示例2: elseif

 /**
  * Get the product row subtotal.
  *
  * Gets the tax etc to avoid rounding issues.
  *
  * When on the checkout (review order), this will get the subtotal based on the customer's tax rate rather than the base rate
  *
  * @params object product
  * @params int quantity
  * @return string formatted price
  */
 function get_product_subtotal($_product, $quantity)
 {
     global $woocommerce;
     $price = $_product->get_price();
     $taxable = $_product->is_taxable();
     $base_tax_rates = $this->tax->get_shop_base_rate($_product->tax_class);
     $tax_rates = $this->tax->get_rates($_product->get_tax_class());
     // This will get the base rate unless we're on the checkout page
     // Taxable
     if ($taxable) {
         if (($this->display_cart_ex_tax || $woocommerce->customer->is_vat_exempt()) && $this->prices_include_tax) {
             $base_taxes = $this->tax->calc_tax($price * $quantity, $base_tax_rates, true);
             $base_tax_amount = array_sum($base_taxes);
             $row_price = $price * $quantity - $base_tax_amount;
             $product_subtotal = woocommerce_price($row_price);
             $product_subtotal .= ' <small class="tax_label">' . $woocommerce->countries->ex_tax_or_vat() . '</small>';
         } elseif (!$this->display_cart_ex_tax && $tax_rates !== $base_tax_rates && $this->prices_include_tax) {
             $base_taxes = $this->tax->calc_tax($price * $quantity, $base_tax_rates, true, true);
             $modded_taxes = $this->tax->calc_tax($price * $quantity - array_sum($base_taxes), $tax_rates, false);
             $row_price = $price * $quantity - array_sum($base_taxes) + array_sum($modded_taxes);
             $product_subtotal = woocommerce_price($row_price);
             if (!$this->prices_include_tax) {
                 $product_subtotal .= ' <small class="tax_label">' . $woocommerce->countries->inc_tax_or_vat() . '</small>';
             }
         } else {
             $row_price = $price * $quantity;
             $product_subtotal = woocommerce_price($row_price);
         }
         // Non taxable
     } else {
         $row_price = $price * $quantity;
         $product_subtotal = woocommerce_price($row_price);
     }
     return apply_filters('woocommerce_cart_product_subtotal', $product_subtotal, $_product, $quantity, $this);
 }
开发者ID:nodar44,项目名称:woocommerce,代码行数:46,代码来源:class-wc-cart.php

示例3: woocommerce_get_price

 public static function woocommerce_get_price($price, $product)
 {
     global $post, $woocommerce;
     $baseprice = $price;
     $result = $baseprice;
     if ($post == null || !is_admin()) {
         if ($product->is_type('variation')) {
             $commission = WRP_Variations_Admin::get_commission($product, $product->variation_id);
         } else {
             $commission = self::get_commission($product);
         }
         if ($commission) {
             $baseprice = $product->get_regular_price();
             if ($product->get_sale_price() != $product->get_regular_price() && $product->get_sale_price() == $product->price) {
                 if (get_option("wrp-baseprice", "regular") == "sale") {
                     $baseprice = $product->get_sale_price();
                 }
             }
             $product_price = $baseprice;
             $type = get_option("wrp-method", "rate");
             $result = 0;
             if ($type == "rate") {
                 // if rate and price includes taxes
                 if ($product->is_taxable() && get_option('woocommerce_prices_include_tax') == 'yes') {
                     $_tax = new WC_Tax();
                     $tax_rates = $_tax->get_shop_base_rate($product->tax_class);
                     $taxes = $_tax->calc_tax($baseprice, $tax_rates, true);
                     $product_price = $_tax->round($baseprice - array_sum($taxes));
                 }
                 $result = self::bcmul($product_price, $commission, WOO_ROLE_PRICING_DECIMALS);
                 if ($product->is_taxable() && get_option('woocommerce_prices_include_tax') == 'yes') {
                     $_tax = new WC_Tax();
                     $tax_rates = $_tax->get_shop_base_rate($product->tax_class);
                     $taxes = $_tax->calc_tax($result, $tax_rates, false);
                     // important false
                     $result = $_tax->round($result + array_sum($taxes));
                 }
             } else {
                 $result = self::bcsub($product_price, $commission, WOO_ROLE_PRICING_DECIMALS);
             }
         }
     }
     return $result;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:44,代码来源:class-woorolepricing.php

示例4: woocommerce_get_price

 public static function woocommerce_get_price($price, $product)
 {
     global $post, $woocommerce;
     $baseprice = $price;
     $result = $baseprice;
     if ($post == null || !is_admin()) {
         $roleprice = self::get_role_price($product);
         if (empty($roleprice)) {
             $regularprice = $product->get_regular_price();
             if (!empty($regularprice)) {
                 $baseprice = $regularprice;
             }
             if ($product->get_sale_price() != $product->get_regular_price() && $product->get_sale_price() == $product->price) {
                 if (get_option("wrp-baseprice", "regular") == "sale") {
                     $baseprice = $product->get_sale_price();
                 }
             }
             $product_price = $baseprice;
         } else {
             $baseprice = $roleprice;
             $product_price = $roleprice;
         }
         $result = 0;
         if ($product->is_taxable() && get_option('woocommerce_prices_include_tax') == 'yes') {
             $_tax = new WC_Tax();
             $tax_rates = $_tax->get_shop_base_rate($product->tax_class);
             $taxes = $_tax->calc_tax($baseprice, $tax_rates, true);
             $product_price = $_tax->round($baseprice - array_sum($taxes));
         }
         $result = $product_price;
         if ($product->is_taxable() && get_option('woocommerce_prices_include_tax') == 'yes') {
             $_tax = new WC_Tax();
             $tax_rates = $_tax->get_shop_base_rate($product->tax_class);
             $taxes = $_tax->calc_tax($result, $tax_rates, false);
             // important false
             $result = $_tax->round($result + array_sum($taxes));
         }
     }
     return $result;
 }
开发者ID:taeche,项目名称:SoDoEx,代码行数:40,代码来源:class-woorolepricinglight.php

示例5: calculate_fees

 /**
  * Calculate fees
  */
 public function calculate_fees()
 {
     // Fire an action where developers can add their fees
     do_action('woocommerce_cart_calculate_fees', $this);
     // If fees were added, total them and calculate tax
     if ($fees = $this->get_fees()) {
         foreach ($fees as $fee) {
             $this->fee_total += $fee->amount;
             if ($fee->taxable) {
                 // Get tax rates
                 $tax_rates = $this->tax->get_rates($fee->tax_class);
                 $fee_taxes = $this->tax->calc_tax($fee->amount, $tax_rates, false);
                 // Store
                 $fee->tax = array_sum($fee_taxes);
                 // Tax rows - merge the totals we just got
                 foreach (array_keys($this->taxes + $fee_taxes) as $key) {
                     $this->taxes[$key] = (isset($fee_taxes[$key]) ? $fee_taxes[$key] : 0) + (isset($this->taxes[$key]) ? $this->taxes[$key] : 0);
                 }
             }
         }
     }
 }
开发者ID:shahadat014,项目名称:geleyi,代码行数:25,代码来源:class-wc-cart.php

示例6: __construct

 public function __construct()
 {
     $this->order = new WC_Order();
     $this->type = 'preview';
     $this->number = get_option('wc_gzdp_invoice_simple') + 1;
     $this->recipient = array('firstname' => _x('Max', 'invoices-preview', 'woocommerce-germanized-pro'), 'lastname' => _x('Mustermann', 'invoices-preview', 'woocommerce-germanized-pro'));
     $this->address = implode('<br/>', array(_x('Max Mustermann', 'invoices-preview', 'woocommerce-germanized-pro'), _x('Musterstraße 35', 'invoices-preview', 'woocommerce-germanized-pro'), _x('12209 Musterstadt', 'invoices-preview', 'woocommerce-germanized-pro')));
     $base_rate = WC_Tax::get_shop_base_rate();
     $base_rate_id = key($base_rate);
     $calc_tax = true;
     if (get_option('woocommerce_gzd_small_enterprise') == 'yes') {
         $calc_tax = false;
     }
     $this->items = array();
     $total = 0;
     $total_tax = 0;
     $shipping = 0;
     for ($i = 0; $i < 30; $i++) {
         $qty = 1;
         $subtotal_gross = 35.95;
         $subtotal_tax = $calc_tax ? array_sum(WC_Tax::calc_tax($subtotal_gross, $base_rate, true)) : 0;
         $subtotal_net = $subtotal_gross - $subtotal_tax;
         $subtotal = $subtotal_net;
         $item_total = $qty * $subtotal;
         $item_tax = $qty * $subtotal_tax;
         $item = array('name' => _x('Testprodukt', 'invoices-preview', 'woocommerce-germanized-pro'), 'item_meta' => array(), 'type' => 'line_item', 'qty' => $qty, 'line_total' => $item_total, 'line_subtotal' => $subtotal, 'line_tax' => $item_tax, 'line_subtotal_tax' => $subtotal_tax);
         $total += $subtotal_gross;
         $total_tax += $item_tax;
         array_push($this->items, $item);
     }
     $this->totals = array('subtotal' => $total - $shipping - $total_tax, 'total' => $total, 'shipping' => $shipping, 'tax' => $total_tax, 'discount' => 0);
     if ($calc_tax) {
         $tax_totals = array('amount' => $total_tax, 'rate_id' => $base_rate_id, 'formatted_amount' => wc_price($total_tax));
         $this->tax_totals = array();
         $this->tax_totals['DE'] = (object) $tax_totals;
     }
 }
开发者ID:radscheit,项目名称:unicorn,代码行数:37,代码来源:class-wc-gzdp-invoice-preview.php

示例7: do_fee_tax_calculation

 /**
  * Recalculate fee taxes to split tax based on different tax rates contained within cart
  *  
  * @param  WC_Cart $cart
  */
 public function do_fee_tax_calculation(WC_Cart $cart)
 {
     if (get_option('woocommerce_gzd_fee_tax') != 'yes') {
         return;
     }
     if (!empty($cart->fees)) {
         $tax_shares = wc_gzd_get_cart_tax_share('fee');
         foreach ($cart->fees as $key => $fee) {
             if (!$fee->taxable && get_option('woocommerce_gzd_fee_tax_force') != 'yes') {
                 continue;
             }
             // Calculate gross price if necessary
             if ($fee->taxable) {
                 $fee_tax_rates = WC_Tax::get_rates($fee->tax_class);
                 $fee_tax = WC_Tax::calc_tax($fee->amount, $fee_tax_rates, false);
                 $fee->amount += array_sum($fee_tax);
             }
             // Set fee to nontaxable to avoid WooCommerce default tax calculation
             $fee->taxable = false;
             // Calculate tax class share
             if (!empty($tax_shares)) {
                 $fee_taxes = array();
                 foreach ($tax_shares as $rate => $class) {
                     $tax_rates = WC_Tax::get_rates($rate);
                     $tax_shares[$rate]['fee_tax_share'] = $fee->amount * $class['share'];
                     $tax_shares[$rate]['fee_tax'] = WC_Tax::calc_tax($fee->amount * $class['share'], $tax_rates, true);
                     $fee_taxes += $tax_shares[$rate]['fee_tax'];
                 }
                 foreach ($tax_shares as $rate => $class) {
                     $cart->fees[$key]->tax_data = $cart->fees[$key]->tax_data + $class['fee_tax'];
                 }
                 // Add fee taxes to cart taxes
                 foreach (array_keys($cart->taxes + $fee_taxes) as $sub) {
                     $cart->taxes[$sub] = (isset($fee_taxes[$sub]) ? $fee_taxes[$sub] : 0) + (isset($cart->taxes[$sub]) ? $cart->taxes[$sub] : 0);
                 }
                 // Update fee
                 $cart->fees[$key]->tax = array_sum($cart->fees[$key]->tax_data);
                 $cart->fees[$key]->amount = $cart->fees[$key]->amount - $cart->fees[$key]->tax;
             }
         }
     }
 }
开发者ID:ronzeiller,项目名称:woocommerce-germanized,代码行数:47,代码来源:class-wc-gzd-checkout.php

示例8: calc_line_taxes

 /**
  * Calc line tax.
  */
 public static function calc_line_taxes()
 {
     global $wpdb;
     check_ajax_referer('calc-totals', 'security');
     if (!current_user_can('edit_shop_orders')) {
         die(-1);
     }
     $tax = new WC_Tax();
     $tax_based_on = get_option('woocommerce_tax_based_on');
     $order_id = absint($_POST['order_id']);
     $items = array();
     $country = strtoupper(esc_attr($_POST['country']));
     $state = strtoupper(esc_attr($_POST['state']));
     $postcode = strtoupper(esc_attr($_POST['postcode']));
     $city = wc_clean(esc_attr($_POST['city']));
     $order = wc_get_order($order_id);
     $taxes = array();
     $shipping_taxes = array();
     $order_item_tax_classes = array();
     // Default to base
     if ('base' === $tax_based_on || empty($country)) {
         $default = wc_get_base_location();
         $country = $default['country'];
         $state = $default['state'];
         $postcode = '';
         $city = '';
     }
     // Parse the jQuery serialized items
     parse_str($_POST['items'], $items);
     // Prevent undefined warnings
     if (!isset($items['line_tax'])) {
         $items['line_tax'] = array();
     }
     if (!isset($items['line_subtotal_tax'])) {
         $items['line_subtotal_tax'] = array();
     }
     $items['order_taxes'] = array();
     // Action
     $items = apply_filters('woocommerce_ajax_calc_line_taxes', $items, $order_id, $country, $_POST);
     $is_vat_exempt = get_post_meta($order_id, '_is_vat_exempt', true);
     // Tax is calculated only if tax is enabled and order is not vat exempted
     if (wc_tax_enabled() && $is_vat_exempt !== 'yes') {
         // Get items and fees taxes
         if (isset($items['order_item_id'])) {
             $line_total = $line_subtotal = array();
             foreach ($items['order_item_id'] as $item_id) {
                 $item_id = absint($item_id);
                 $line_total[$item_id] = isset($items['line_total'][$item_id]) ? wc_format_decimal($items['line_total'][$item_id]) : 0;
                 $line_subtotal[$item_id] = isset($items['line_subtotal'][$item_id]) ? wc_format_decimal($items['line_subtotal'][$item_id]) : $line_total[$item_id];
                 $order_item_tax_classes[$item_id] = isset($items['order_item_tax_class'][$item_id]) ? sanitize_text_field($items['order_item_tax_class'][$item_id]) : '';
                 $product_id = $order->get_item_meta($item_id, '_product_id', true);
                 // Get product details
                 if (get_post_type($product_id) == 'product') {
                     $_product = wc_get_product($product_id);
                     $item_tax_status = $_product->get_tax_status();
                 } else {
                     $item_tax_status = 'taxable';
                 }
                 if ('0' !== $order_item_tax_classes[$item_id] && 'taxable' === $item_tax_status) {
                     $tax_rates = WC_Tax::find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $order_item_tax_classes[$item_id]));
                     $line_taxes = WC_Tax::calc_tax($line_total[$item_id], $tax_rates, false);
                     $line_subtotal_taxes = WC_Tax::calc_tax($line_subtotal[$item_id], $tax_rates, false);
                     // Set the new line_tax
                     foreach ($line_taxes as $_tax_id => $_tax_value) {
                         $items['line_tax'][$item_id][$_tax_id] = $_tax_value;
                     }
                     // Set the new line_subtotal_tax
                     foreach ($line_subtotal_taxes as $_tax_id => $_tax_value) {
                         $items['line_subtotal_tax'][$item_id][$_tax_id] = $_tax_value;
                     }
                     // Sum the item taxes
                     foreach (array_keys($taxes + $line_taxes) as $key) {
                         $taxes[$key] = (isset($line_taxes[$key]) ? $line_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
                     }
                 }
             }
         }
         // Get shipping taxes
         if (isset($items['shipping_method_id'])) {
             $matched_tax_rates = array();
             $order_item_tax_classes = array_unique(array_values($order_item_tax_classes));
             // If multiple classes are found, use the first one. Don't bother with standard rate, we can get that later.
             if (sizeof($order_item_tax_classes) > 1 && !in_array('', $order_item_tax_classes)) {
                 $tax_classes = WC_Tax::get_tax_classes();
                 foreach ($tax_classes as $tax_class) {
                     $tax_class = sanitize_title($tax_class);
                     if (in_array($tax_class, $order_item_tax_classes)) {
                         $matched_tax_rates = WC_Tax::find_shipping_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $tax_class));
                         break;
                     }
                 }
                 // If a single tax class is found, use it
             } elseif (sizeof($order_item_tax_classes) === 1) {
                 $matched_tax_rates = WC_Tax::find_shipping_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $order_item_tax_classes[0]));
             }
             // Get standard rate if no taxes were found
             if (!sizeof($matched_tax_rates)) {
//.........这里部分代码省略.........
开发者ID:AndyA,项目名称:River,代码行数:101,代码来源:class-wc-ajax.php

示例9: sync

 public function sync()
 {
     global $wp;
     global $wpdb;
     set_time_limit(0);
     @ini_set('display_errors', '1');
     @ini_set('zlib.output_compression', 'Off');
     @ini_set('output_buffering', 'Off');
     @ini_set('output_handler', '');
     while (ob_get_level() > 1) {
         @ob_end_clean();
     }
     if (ob_get_level() > 0) {
         @ob_clean();
     }
     if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
         $this->sendHttpHeaders('500 Config Error', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache'));
         echo $this->json_encode(array('ack' => 'failed', 'message' => 'WooCommerce Deactivated'));
         exit;
     }
     $type = $wp->query_vars['codisto-sync-route'];
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
         if ($type == 'test' || $type == 'sync' && preg_match('/\\/sync\\/testHash\\?/', $_SERVER['REQUEST_URI'])) {
             if (!$this->check_hash()) {
                 exit;
             }
             $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache'));
             echo $this->json_encode(array('ack' => 'ok'));
         } else {
             if ($type === 'settings') {
                 if (!$this->check_hash()) {
                     exit;
                 }
                 $logo_url = get_header_image();
                 if (function_exists('site_logo')) {
                     $logo = site_logo()->logo;
                     $logo_id = get_theme_mod('custom_logo');
                     $logo_id = $logo_id ? $logo_id : $logo['id'];
                     if ($logo_id) {
                         $logo_url = wp_get_attachment_image_src($logo_id, 'full');
                         $logo_url = $logo_url[0];
                     }
                 }
                 $currency = get_option('woocommerce_currency');
                 $dimension_unit = get_option('woocommerce_dimension_unit');
                 $weight_unit = get_option('woocommerce_weight_unit');
                 $default_location = explode(':', get_option('woocommerce_default_country'));
                 $country_code = isset($default_location[0]) ? $default_location[0] : '';
                 $state_code = isset($default_location[1]) ? $default_location[1] : '';
                 $response = array('ack' => 'ok', 'logo' => $logo_url, 'currency' => $currency, 'dimension_unit' => $dimension_unit, 'weight_unit' => $weight_unit, 'country_code' => $country_code, 'state_code' => $state_code);
                 $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache'));
                 echo $this->json_encode($response);
                 exit;
             } else {
                 if ($type === 'tax') {
                     if (!$this->check_hash()) {
                         exit;
                     }
                     $tax_enabled = true;
                     if (function_exists('wc_tax_enabled')) {
                         $tax_enabled = wc_tax_enabled();
                     } else {
                         $tax_enabled = get_option('woocommerce_calc_taxes') === 'yes';
                     }
                     if ($tax_enabled) {
                         $rates = $wpdb->get_results("SELECT tax_rate_country AS country, tax_rate_state AS state, tax_rate AS rate, tax_rate_name AS name, tax_rate_class AS class, tax_rate_order AS sequence, tax_rate_priority AS priority FROM `{$wpdb->prefix}woocommerce_tax_rates` ORDER BY tax_rate_order");
                     } else {
                         $rates = array();
                     }
                     $response = array('ack' => 'ok', 'tax_rates' => $rates);
                     $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache'));
                     echo $this->json_encode($response);
                     exit;
                 } else {
                     if ($type === 'products') {
                         if (!$this->check_hash()) {
                             exit;
                         }
                         $page = isset($_GET['page']) ? (int) $_GET['page'] : 0;
                         $count = isset($_GET['count']) ? (int) $_GET['count'] : 0;
                         $product_ids = isset($_GET['product_ids']) ? json_decode(wp_unslash($_GET['product_ids'])) : null;
                         if (!is_null($product_ids)) {
                             if (!is_array($product_ids)) {
                                 $product_ids = array($product_ids);
                             }
                             $product_ids = array_filter($product_ids, create_function('$v', 'return is_numeric($v);'));
                             if (!isset($_GET['count'])) {
                                 $count = count($product_ids);
                             }
                         }
                         $products = $wpdb->get_results($wpdb->prepare("SELECT id AS id " . "FROM `{$wpdb->prefix}posts` AS P " . "WHERE post_type = 'product' " . "\t\tAND post_status IN ('publish', 'future', 'pending', 'private') " . "\t" . (is_array($product_ids) ? 'AND id IN (' . implode(',', $product_ids) . ')' : '') . "" . "ORDER BY ID LIMIT %d, %d", $page * $count, $count));
                         if (!is_array($product_ids) && $page === 0) {
                             $total_count = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}posts` WHERE post_type = 'product' AND post_status IN ('publish', 'future', 'pending', 'private')");
                         }
                         $acf_installed = function_exists('acf');
                         foreach ($products as $product) {
                             $wc_product = $this->get_product($product->id);
                             $categoryproduct = $wc_product->get_categories();
                             $product->sku = $wc_product->get_sku();
                             $product->name = html_entity_decode(apply_filters('woocommerce_product_title', $wc_product->post->post_title, $wc_product), ENT_COMPAT | ENT_HTML401, 'UTF-8');
//.........这里部分代码省略.........
开发者ID:CodistoConnect,项目名称:CodistoConnect-WooCommerce,代码行数:101,代码来源:connect.php

示例10: calculate_taxes

 /**
  * Calculate taxes for all line items and shipping, and store the totals and tax rows.
  *
  * Will use the base country unless customer addresses are set.
  *
  * @return bool success or fail
  */
 public function calculate_taxes()
 {
     $tax_total = 0;
     $taxes = array();
     $tax_based_on = get_option('woocommerce_tax_based_on');
     if ('billing' === $tax_based_on) {
         $country = $this->billing_country;
         $state = $this->billing_state;
         $postcode = $this->billing_postcode;
         $city = $this->billing_city;
     } elseif ('shipping' === $tax_based_on) {
         $country = $this->shipping_country;
         $state = $this->shipping_state;
         $postcode = $this->shipping_postcode;
         $city = $this->shipping_city;
     }
     // Default to base
     if ('base' === $tax_based_on || empty($country)) {
         $default = wc_get_base_location();
         $country = $default['country'];
         $state = $default['state'];
         $postcode = '';
         $city = '';
     }
     // Get items
     foreach ($this->get_items(array('line_item', 'fee')) as $item_id => $item) {
         $product = $this->get_product_from_item($item);
         $line_total = isset($item['line_total']) ? $item['line_total'] : 0;
         $line_subtotal = isset($item['line_subtotal']) ? $item['line_subtotal'] : 0;
         $tax_class = $item['tax_class'];
         $item_tax_status = $product ? $product->get_tax_status() : 'taxable';
         if ('0' !== $tax_class && 'taxable' === $item_tax_status) {
             $tax_rates = WC_Tax::find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $tax_class));
             $line_subtotal_taxes = WC_Tax::calc_tax($line_subtotal, $tax_rates, false);
             $line_taxes = WC_Tax::calc_tax($line_total, $tax_rates, false);
             $line_subtotal_tax = max(0, array_sum($line_subtotal_taxes));
             $line_tax = max(0, array_sum($line_taxes));
             $tax_total += $line_tax;
             wc_update_order_item_meta($item_id, '_line_subtotal_tax', wc_format_decimal($line_subtotal_tax));
             wc_update_order_item_meta($item_id, '_line_tax', wc_format_decimal($line_tax));
             wc_update_order_item_meta($item_id, '_line_tax_data', array('total' => $line_taxes, 'subtotal' => $line_subtotal_taxes));
             // Sum the item taxes
             foreach (array_keys($taxes + $line_taxes) as $key) {
                 $taxes[$key] = (isset($line_taxes[$key]) ? $line_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
             }
         }
     }
     // Now calculate shipping tax
     $matched_tax_rates = array();
     $tax_rates = WC_Tax::find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => ''));
     if (!empty($tax_rates)) {
         foreach ($tax_rates as $key => $rate) {
             if (isset($rate['shipping']) && 'yes' === $rate['shipping']) {
                 $matched_tax_rates[$key] = $rate;
             }
         }
     }
     $shipping_taxes = WC_Tax::calc_shipping_tax($this->order_shipping, $matched_tax_rates);
     $shipping_tax_total = WC_Tax::round(array_sum($shipping_taxes));
     // Save tax totals
     $this->set_total($shipping_tax_total, 'shipping_tax');
     $this->set_total($tax_total, 'tax');
     // Tax rows
     $this->remove_order_items('tax');
     // Now merge to keep tax rows
     foreach (array_keys($taxes + $shipping_taxes) as $tax_rate_id) {
         $this->add_tax($tax_rate_id, isset($taxes[$tax_rate_id]) ? $taxes[$tax_rate_id] : 0, isset($shipping_taxes[$tax_rate_id]) ? $shipping_taxes[$tax_rate_id] : 0);
     }
     return true;
 }
开发者ID:danisdead,项目名称:gastrointernacional,代码行数:77,代码来源:abstract-wc-order.php

示例11: 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

示例12: calc_line_taxes

 /**
  * Calc line tax
  */
 public static function calc_line_taxes()
 {
     global $wpdb;
     check_ajax_referer('calc-totals', 'security');
     if (!current_user_can('edit_shop_orders')) {
         die(-1);
     }
     $tax = new WC_Tax();
     $order_id = absint($_POST['order_id']);
     $items = array();
     $country = strtoupper(esc_attr($_POST['country']));
     $state = strtoupper(esc_attr($_POST['state']));
     $postcode = strtoupper(esc_attr($_POST['postcode']));
     $city = wc_clean(esc_attr($_POST['city']));
     $order = wc_get_order($order_id);
     $taxes = array();
     $shipping_taxes = array();
     // Parse the jQuery serialized items
     parse_str($_POST['items'], $items);
     // Prevent undefined warnings
     if (!isset($items['line_tax'])) {
         $items['line_tax'] = array();
     }
     if (!isset($items['line_subtotal_tax'])) {
         $items['line_subtotal_tax'] = array();
     }
     $items['order_taxes'] = array();
     // Action
     $items = apply_filters('woocommerce_ajax_calc_line_taxes', $items, $order_id, $country, $_POST);
     // Get items and fees taxes
     if (isset($items['order_item_id'])) {
         $line_total = $line_subtotal = $order_item_tax_class = array();
         foreach ($items['order_item_id'] as $item_id) {
             $item_id = absint($item_id);
             $line_total[$item_id] = isset($items['line_total'][$item_id]) ? wc_format_decimal($items['line_total'][$item_id]) : 0;
             $line_subtotal[$item_id] = isset($items['line_subtotal'][$item_id]) ? wc_format_decimal($items['line_subtotal'][$item_id]) : $line_total[$item_id];
             $order_item_tax_class[$item_id] = isset($items['order_item_tax_class'][$item_id]) ? sanitize_text_field($items['order_item_tax_class'][$item_id]) : '';
             $product_id = $order->get_item_meta($item_id, '_product_id', true);
             // Get product details
             if (get_post_type($product_id) == 'product') {
                 $_product = wc_get_product($product_id);
                 $item_tax_status = $_product->get_tax_status();
             } else {
                 $item_tax_status = 'taxable';
             }
             if ('0' !== $order_item_tax_class[$item_id] && 'taxable' === $item_tax_status) {
                 $tax_rates = WC_Tax::find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $order_item_tax_class[$item_id]));
                 $line_taxes = WC_Tax::calc_tax($line_total[$item_id], $tax_rates, false);
                 $line_subtotal_taxes = WC_Tax::calc_tax($line_subtotal[$item_id], $tax_rates, false);
                 // Set the new line_tax
                 foreach ($line_taxes as $_tax_id => $_tax_value) {
                     $items['line_tax'][$item_id][$_tax_id] = $_tax_value;
                 }
                 // Set the new line_subtotal_tax
                 foreach ($line_subtotal_taxes as $_tax_id => $_tax_value) {
                     $items['line_subtotal_tax'][$item_id][$_tax_id] = $_tax_value;
                 }
                 // Sum the item taxes
                 foreach (array_keys($taxes + $line_taxes) as $key) {
                     $taxes[$key] = (isset($line_taxes[$key]) ? $line_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
                 }
             }
         }
     }
     // Get shipping taxes
     if (isset($items['shipping_method_id'])) {
         $matched_tax_rates = array();
         $tax_rates = WC_Tax::find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => ''));
         if ($tax_rates) {
             foreach ($tax_rates as $key => $rate) {
                 if (isset($rate['shipping']) && 'yes' == $rate['shipping']) {
                     $matched_tax_rates[$key] = $rate;
                 }
             }
         }
         $shipping_cost = $shipping_taxes = array();
         foreach ($items['shipping_method_id'] as $item_id) {
             $item_id = absint($item_id);
             $shipping_cost[$item_id] = isset($items['shipping_cost'][$item_id]) ? wc_format_decimal($items['shipping_cost'][$item_id]) : 0;
             $_shipping_taxes = WC_Tax::calc_shipping_tax($shipping_cost[$item_id], $matched_tax_rates);
             // Set the new shipping_taxes
             foreach ($_shipping_taxes as $_tax_id => $_tax_value) {
                 $items['shipping_taxes'][$item_id][$_tax_id] = $_tax_value;
                 $shipping_taxes[$_tax_id] = isset($shipping_taxes[$_tax_id]) ? $shipping_taxes[$_tax_id] + $_tax_value : $_tax_value;
             }
         }
     }
     // Remove old tax rows
     $order->remove_order_items('tax');
     // Add tax rows
     foreach (array_keys($taxes + $shipping_taxes) as $tax_rate_id) {
         $order->add_tax($tax_rate_id, isset($taxes[$tax_rate_id]) ? $taxes[$tax_rate_id] : 0, isset($shipping_taxes[$tax_rate_id]) ? $shipping_taxes[$tax_rate_id] : 0);
     }
     // Create the new order_taxes
     foreach ($order->get_taxes() as $tax_id => $tax_item) {
         $items['order_taxes'][$tax_id] = absint($tax_item['rate_id']);
     }
//.........这里部分代码省略.........
开发者ID:JodiWarren,项目名称:woocommerce,代码行数:101,代码来源:class-wc-ajax.php

示例13: round

 /**
  * Returns the price (excluding tax) - ignores tax_class filters since the price may *include* tax and thus needs subtracting.
  *
  * @access public
  * @return string
  */
 function get_price_excluding_tax()
 {
     $price = $this->get_price();
     if ($this->is_taxable() && get_option('woocommerce_prices_include_tax') == 'yes') {
         $_tax = new WC_Tax();
         $tax_rates = $_tax->get_shop_base_rate($this->tax_class);
         $taxes = $_tax->calc_tax($price, $tax_rates, true);
         $tax_amount = $_tax->get_tax_total($taxes);
         $price = round($price - $tax_amount, 2);
     }
     return apply_filters('woocommerce_get_price_excluding_tax', $price, $this);
 }
开发者ID:vjdesign,项目名称:fontaine,代码行数:18,代码来源:class-wc-product.php

示例14: vtprd_get_price_excluding_tax_forced

function vtprd_get_price_excluding_tax_forced($product_id, $price, $product)
{
    global $post, $wpdb, $woocommerce, $vtprd_cart, $vtprd_cart_item, $vtprd_setup_options, $vtprd_info;
    //changed $this->  to  $product->
    //use $discount_price as basis
    $qty = 1;
    if ($product->is_taxable()) {
        //if ( $product->is_taxable() && get_option('woocommerce_prices_include_tax') === 'yes' ) {
        $_tax = new WC_Tax();
        $tax_rates = $_tax->get_shop_base_rate($product->tax_class);
        $taxes = $_tax->calc_tax($price * $qty, $tax_rates, true);
        $price = $_tax->round($price * $qty - array_sum($taxes));
    }
    return $price;
}
开发者ID:k2jysy,项目名称:kshop,代码行数:15,代码来源:vtprd-parent-functions.php

示例15: output

 /**
  * Output the form
  */
 public function output()
 {
     $this->errors = array();
     $step = 1;
     try {
         if (!empty($_POST) && !check_admin_referer('create_booking_notification')) {
             throw new Exception(__('Error - please try again', 'woocommerce-bookings'));
         }
         if (!empty($_POST['create_booking'])) {
             $customer_id = absint($_POST['customer_id']);
             $bookable_product_id = absint($_POST['bookable_product_id']);
             $booking_order = wc_clean($_POST['booking_order']);
             if (!$bookable_product_id) {
                 throw new Exception(__('Please choose a bookable product', 'woocommerce-bookings'));
             }
             if ($booking_order === 'existing') {
                 $order_id = absint($_POST['booking_order_id']);
                 $booking_order = $order_id;
                 if (!$booking_order || get_post_type($booking_order) !== 'shop_order') {
                     throw new Exception(__('Invalid order ID provided', 'woocommerce-bookings'));
                 }
             }
             $step++;
             $product = get_product($bookable_product_id);
             $booking_form = new WC_Booking_Form($product);
         } elseif (!empty($_POST['create_booking_2'])) {
             $customer_id = absint($_POST['customer_id']);
             $bookable_product_id = absint($_POST['bookable_product_id']);
             $booking_order = wc_clean($_POST['booking_order']);
             $product = get_product($bookable_product_id);
             $booking_form = new WC_Booking_Form($product);
             $booking_data = $booking_form->get_posted_data($_POST);
             $booking_cost = ($cost = $booking_form->calculate_booking_cost($_POST)) && !is_wp_error($cost) ? number_format($cost, 2, '.', '') : 0;
             $create_order = false;
             if ('yes' === get_option('woocommerce_prices_include_tax')) {
                 if (version_compare(WOOCOMMERCE_VERSION, '2.3', '<')) {
                     $base_tax_rates = WC_Tax::get_shop_base_rate($product->tax_class);
                 } else {
                     $base_tax_rates = WC_Tax::get_base_tax_rates($product->tax_class);
                 }
                 $base_taxes = WC_Tax::calc_tax($booking_cost, $base_tax_rates, true);
                 $booking_cost = round($booking_cost - array_sum($base_taxes), absint(get_option('woocommerce_price_num_decimals')));
             }
             // Data to go into the booking
             $new_booking_data = array('user_id' => $customer_id, 'product_id' => $product->id, 'resource_id' => isset($booking_data['_resource_id']) ? $booking_data['_resource_id'] : '', 'persons' => $booking_data['_persons'], 'cost' => $booking_cost, 'start_date' => $booking_data['_start_date'], 'end_date' => $booking_data['_end_date'], 'all_day' => $booking_data['_all_day'] ? 1 : 0);
             // Create order
             if ($booking_order === 'new') {
                 $create_order = true;
                 $order_id = $this->create_order($booking_cost, $customer_id);
                 if (!$order_id) {
                     throw new Exception(__('Error: Could not create order', 'woocommerce-bookings'));
                 }
             } elseif ($booking_order > 0) {
                 $order_id = absint($booking_order);
                 if (!$order_id || get_post_type($order_id) !== 'shop_order') {
                     throw new Exception(__('Invalid order ID provided', 'woocommerce-bookings'));
                 }
                 $order = new WC_Order($order_id);
                 update_post_meta($order_id, '_order_total', $order->get_total() + $booking_cost);
                 update_post_meta($order_id, '_booking_order', '1');
             } else {
                 $order_id = 0;
             }
             if ($order_id) {
                 $item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $product->get_title(), 'order_item_type' => 'line_item'));
                 if (!$item_id) {
                     throw new Exception(__('Error: Could not create item', 'woocommerce-bookings'));
                 }
                 // Add line item meta
                 woocommerce_add_order_item_meta($item_id, '_qty', 1);
                 woocommerce_add_order_item_meta($item_id, '_tax_class', $product->get_tax_class());
                 woocommerce_add_order_item_meta($item_id, '_product_id', $product->id);
                 woocommerce_add_order_item_meta($item_id, '_variation_id', '');
                 woocommerce_add_order_item_meta($item_id, '_line_subtotal', $booking_cost);
                 woocommerce_add_order_item_meta($item_id, '_line_total', $booking_cost);
                 woocommerce_add_order_item_meta($item_id, '_line_tax', 0);
                 woocommerce_add_order_item_meta($item_id, '_line_subtotal_tax', 0);
                 // We have an item id
                 $new_booking_data['order_item_id'] = $item_id;
                 // Add line item data
                 foreach ($booking_data as $key => $value) {
                     if (strpos($key, '_') !== 0) {
                         woocommerce_add_order_item_meta($item_id, get_wc_booking_data_label($key, $product), $value);
                     }
                 }
             }
             // Create the booking itself
             $new_booking = get_wc_booking($new_booking_data);
             $new_booking->create($create_order ? 'unpaid' : 'pending-confirmation');
             wp_safe_redirect(admin_url('post.php?post=' . ($create_order ? $order_id : $new_booking->id) . '&action=edit'));
             exit;
         }
     } catch (Exception $e) {
         $this->errors[] = $e->getMessage();
     }
     switch ($step) {
         case 1:
//.........这里部分代码省略.........
开发者ID:tonyvu1985,项目名称:appletutorings,代码行数:101,代码来源:class-wc-bookings-create.php


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