本文整理汇总了PHP中WC_Tax类的典型用法代码示例。如果您正苦于以下问题:PHP WC_Tax类的具体用法?PHP WC_Tax怎么用?PHP WC_Tax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WC_Tax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: create_order
/**
* Create a order.
*
* @since 2.4
*
* @return WC_Order Order object.
*/
public static function create_order()
{
// Create product
$product = WC_Helper_Product::create_simple_product();
WC_Helper_Shipping::create_simple_flat_rate();
$order_data = array('status' => 'pending', 'customer_id' => 1, 'customer_note' => '', 'total' => '');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
// Required, else wc_create_order throws an exception
$order = wc_create_order($order_data);
// Add order products
$item_id = $order->add_product($product, 4);
// Set billing address
$billing_address = array('country' => 'US', 'first_name' => 'Jeroen', 'last_name' => 'Sormani', 'company' => 'WooCompany', 'address_1' => 'WooAddress', 'address_2' => '', 'postcode' => '123456', 'city' => 'WooCity', 'state' => 'NY', 'email' => '[email protected]', 'phone' => '555-32123');
$order->set_address($billing_address, 'billing');
// Add shipping costs
$shipping_taxes = WC_Tax::calc_shipping_tax('10', WC_Tax::get_shipping_tax_rates());
$order->add_shipping(new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate'));
// Set payment gateway
$payment_gateways = WC()->payment_gateways->payment_gateways();
$order->set_payment_method($payment_gateways['bacs']);
// Set totals
$order->set_total(10, 'shipping');
$order->set_total(0, 'cart_discount');
$order->set_total(0, 'cart_discount_tax');
$order->set_total(0, 'tax');
$order->set_total(0, 'shipping_tax');
$order->set_total(40, 'total');
// 4 x $10 simple helper product
return wc_get_order($order->id);
}
开发者ID:bitoncoin,项目名称:woocommerce,代码行数:37,代码来源:class-wc-helper-order.php
示例2: create_order
/**
* Create a order.
*
* @since 2.4
*
* @return WC_Order Order object.
*/
public static function create_order($customer_id = 1)
{
// Create product
$product = WC_Helper_Product::create_simple_product();
WC_Helper_Shipping::create_simple_flat_rate();
$order_data = array('status' => 'pending', 'customer_id' => $customer_id, 'customer_note' => '', 'total' => '');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
// Required, else wc_create_order throws an exception
$order = wc_create_order($order_data);
// Add order products
$order->add_product($product, 4);
// Set billing address
$order->set_billing_first_name('Jeroen');
$order->set_billing_last_name('Sormani');
$order->set_billing_company('WooCompany');
$order->set_billing_address_1('WooAddress');
$order->set_billing_address_2('');
$order->set_billing_city('WooCity');
$order->set_billing_state('NY');
$order->set_billing_postcode('123456');
$order->set_billing_country('US');
$order->set_billing_email('[email protected]');
$order->set_billing_phone('555-32123');
// Add shipping costs
$shipping_taxes = WC_Tax::calc_shipping_tax('10', WC_Tax::get_shipping_tax_rates());
$rate = new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate');
$item = new WC_Order_Item_Shipping();
$item->set_props(array('method_title' => $rate->label, 'method_id' => $rate->id, 'total' => wc_format_decimal($rate->cost), 'taxes' => $rate->taxes, 'meta_data' => $rate->get_meta_data()));
$order->add_item($item);
// Set payment gateway
$payment_gateways = WC()->payment_gateways->payment_gateways();
$order->set_payment_method($payment_gateways['bacs']);
// Set totals
$order->set_shipping_total(10);
$order->set_discount_total(0);
$order->set_discount_tax(0);
$order->set_cart_tax(0);
$order->set_shipping_tax(0);
$order->set_total(40);
// 4 x $10 simple helper product
$order->save();
return $order;
}
开发者ID:woocommerce,项目名称:woocommerce,代码行数:50,代码来源:class-wc-helper-order.php
示例3: calculate_shipping
/**
* Calculate shipping when this method is used standalone.
*/
public function calculate_shipping($package)
{
$_tax = new WC_Tax();
$taxes = array();
$shipping_cost = 0;
// This shipping method loops through products, adding up the cost
if (sizeof($package['contents']) > 0) {
foreach ($package['contents'] as $item_id => $values) {
if ($values['quantity'] > 0) {
if ($values['data']->needs_shipping()) {
$rule = false;
$item_shipping_cost = 0;
if ($values['variation_id']) {
$rule = woocommerce_per_product_shipping_get_matching_rule($values['variation_id'], $package);
}
if ($rule === false) {
$rule = woocommerce_per_product_shipping_get_matching_rule($values['product_id'], $package);
}
if ($rule) {
$item_shipping_cost += $rule->rule_item_cost * $values['quantity'];
$item_shipping_cost += $rule->rule_cost;
} elseif ($this->cost === '0' || $this->cost > 0) {
// Use default
$item_shipping_cost += $this->cost * $values['quantity'];
} else {
// NO default and nothing found - abort
return;
}
// Fee
$item_shipping_cost += $this->get_fee($this->fee, $item_shipping_cost) * $values['quantity'];
$shipping_cost += $item_shipping_cost;
if (get_option('woocommerce_calc_taxes') == 'yes' && $this->tax_status == 'taxable') {
$rates = $_tax->get_shipping_tax_rates($values['data']->get_tax_class());
$item_taxes = $_tax->calc_shipping_tax($item_shipping_cost, $rates);
// Sum the item taxes
foreach (array_keys($taxes + $item_taxes) as $key) {
$taxes[$key] = (isset($item_taxes[$key]) ? $item_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
}
}
}
}
}
}
// Add order shipping cost + tax
if ($this->order_fee) {
$order_fee = $this->get_fee($this->order_fee, $shipping_cost);
$shipping_cost += $order_fee;
if (get_option('woocommerce_calc_taxes') == 'yes' && $this->tax_status == 'taxable') {
$rates = $_tax->get_shipping_tax_rates();
$item_taxes = $_tax->calc_shipping_tax($order_fee, $rates);
// Sum the item taxes
foreach (array_keys($taxes + $item_taxes) as $key) {
$taxes[$key] = (isset($item_taxes[$key]) ? $item_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
}
}
}
// Add rate
$this->add_rate(array('id' => $this->id, 'label' => $this->title, 'cost' => $shipping_cost, 'taxes' => $taxes));
}
开发者ID:NoviumDesign,项目名称:polefitness,代码行数:62,代码来源:class-wc-shipping-per-product.php
示例4: add_rate
/**
* Add a rate
*
* Add a shipping rate. If taxes are not set they will be calculated based on cost.
*
* @access public
* @param array $args (default: array())
* @return void
*/
function add_rate($args = array())
{
global $woocommerce;
$defaults = array('id' => '', 'label' => '', 'cost' => '0', 'taxes' => '', 'calc_tax' => 'per_order');
$args = wp_parse_args($args, $defaults);
extract($args);
// Id and label are required
if (!$id || !$label) {
return;
}
// Handle cost
$total_cost = is_array($cost) ? array_sum($cost) : $cost;
// Taxes - if not an array and not set to false, calc tax based on cost and passed calc_tax variable
// This saves shipping methods having to do complex tax calculations
if (!is_array($taxes) && $taxes !== false && $total_cost > 0 && get_option('woocommerce_calc_taxes') == 'yes' && $this->tax_status == 'taxable') {
$_tax = new WC_Tax();
$taxes = array();
switch ($calc_tax) {
case "per_item":
// If we have an array of costs we can look up each items tax class and add tax accordingly
if (is_array($cost)) {
$cart = $woocommerce->cart->get_cart();
foreach ($cost as $cost_key => $amount) {
if (!isset($cart[$cost_key])) {
continue;
}
$_product = $cart[$cost_key]['data'];
$rates = $_tax->get_shipping_tax_rates($_product->get_tax_class());
$item_taxes = $_tax->calc_shipping_tax($amount, $rates);
// Sum the item taxes
foreach (array_keys($taxes + $item_taxes) as $key) {
$taxes[$key] = (isset($item_taxes[$key]) ? $item_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
}
}
// Add any cost for the order - order costs are in the key 'order'
if (isset($cost['order'])) {
$rates = $_tax->get_shipping_tax_rates();
$item_taxes = $_tax->calc_shipping_tax($cost['order'], $rates);
// Sum the item taxes
foreach (array_keys($taxes + $item_taxes) as $key) {
$taxes[$key] = (isset($item_taxes[$key]) ? $item_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
}
}
}
break;
default:
$rates = $_tax->get_shipping_tax_rates();
$taxes = $_tax->calc_shipping_tax($total_cost, $rates);
break;
}
}
$this->rates[] = new WC_Shipping_Rate($id, $label, $total_cost, $taxes, $this->id);
}
开发者ID:joshquila,项目名称:demo2-youse,代码行数:62,代码来源:abstract-wc-shipping-method.php
示例5: get_formatted_order_total
/**
* Gets order total - formatted for display.
*
* @return string
*/
public function get_formatted_order_total($tax_display = '', $display_refunded = true)
{
$formatted_total = wc_price($this->get_total(), array('currency' => $this->get_order_currency()));
$order_total = $this->get_total();
$total_refunded = $this->get_total_refunded();
$tax_string = '';
// Tax for inclusive prices
if (wc_tax_enabled() && 'incl' == $tax_display) {
$tax_string_array = array();
if ('itemized' == get_option('woocommerce_tax_total_display')) {
foreach ($this->get_tax_totals() as $code => $tax) {
$tax_amount = $total_refunded && $display_refunded ? wc_price(WC_Tax::round($tax->amount - $this->get_total_tax_refunded_by_rate_id($tax->rate_id)), array('currency' => $this->get_order_currency())) : $tax->formatted_amount;
$tax_string_array[] = sprintf('%s %s', $tax_amount, $tax->label);
}
} else {
$tax_amount = $total_refunded && $display_refunded ? $this->get_total_tax() - $this->get_total_tax_refunded() : $this->get_total_tax();
$tax_string_array[] = sprintf('%s %s', wc_price($tax_amount, array('currency' => $this->get_order_currency())), WC()->countries->tax_or_vat());
}
if (!empty($tax_string_array)) {
$tax_string = ' ' . sprintf(__('(Includes %s)', 'woocommerce'), implode(', ', $tax_string_array));
}
}
if ($total_refunded && $display_refunded) {
$formatted_total = '<del>' . strip_tags($formatted_total) . '</del> <ins>' . wc_price($order_total - $total_refunded, array('currency' => $this->get_order_currency())) . $tax_string . '</ins>';
} else {
$formatted_total .= $tax_string;
}
return apply_filters('woocommerce_get_formatted_order_total', $formatted_total, $this);
}
开发者ID:magicdustwebsites,项目名称:woocommerce,代码行数:34,代码来源:class-wc-order.php
示例6: set_tax_class
/**
* Set tax class.
*
* @param string $value
* @throws WC_Data_Exception
*/
public function set_tax_class($value)
{
if ($value && !in_array($value, WC_Tax::get_tax_classes())) {
$this->error('order_item_fee_invalid_tax_class', __('Invalid tax class', 'woocommerce'));
}
$this->set_prop('tax_class', $value);
}
开发者ID:woocommerce,项目名称:woocommerce,代码行数:13,代码来源:class-wc-order-item-fee.php
示例7: save_tax_rate_hidden_status
/**
* Whenever a WooCommerce tax rate is saved, also save the tax rate's hidden status.
*
* Executed whenever a WooCommerce tax rate is added, updated or deleted.
*
* @param int $tax_rate_id The WooCommerce Tax Rate ID.
*/
public function save_tax_rate_hidden_status()
{
// nonce and cap checks are copied from WC_AJAX::tax_rates_save_changes()
// Use return instead of exit so that WooCommerce core will handle the AJAX error messages
if (!isset($_POST['wc_tax_nonce'], $_POST['changes'])) {
return;
}
$current_class = !empty($_POST['current_class']) ? $_POST['current_class'] : '';
// This is sanitized seven lines later.
if (!wp_verify_nonce($_POST['wc_tax_nonce'], 'wc_tax_nonce-class:' . $current_class)) {
return;
}
// Check User Caps
if (!current_user_can('manage_woocommerce')) {
return;
}
$hidden_rates = array();
$current_class = WC_Tax::format_tax_rate_class($current_class);
$rates = WC_Tax::get_rates_for_tax_class($current_class);
foreach ($rates as $tax_rate_id => $rate) {
if (isset($_POST['tax_rate_hidden'][$tax_rate_id])) {
// @codingStandardsIgnoreEnd
$hidden_rates[$tax_rate_id] = true;
} else {
if (isset($hidden_rates[$tax_rate_id])) {
unset($hidden_rates[$tax_rate_id]);
}
}
}
wc_hidden_taxes()->set_option('hidden_rates', $hidden_rates);
}
开发者ID:OM4,项目名称:woocommerce-hidden-taxes,代码行数:38,代码来源:wc-hidden-taxes-admin.php
示例8: test_cart_get_discounted_price
/**
* Test some discount logic which has caused issues in the past.
* Tickets:
* https://github.com/woothemes/woocommerce/issues/10573
* https://github.com/woothemes/woocommerce/issues/10963
*
* Due to discounts being split amongst products in cart.
*/
public function test_cart_get_discounted_price()
{
global $wpdb;
// We need this to have the calculate_totals() method calculate totals
if (!defined('WOOCOMMERCE_CHECKOUT')) {
define('WOOCOMMERCE_CHECKOUT', true);
}
# Test case 1 #10963
// Create dummy coupon - fixed cart, 1 value
$coupon = WC_Helper_Coupon::create_coupon();
// Add coupon
WC()->cart->add_discount($coupon->code);
// Create dummy product - price will be 10
$product = WC_Helper_Product::create_simple_product();
// Add product to cart x1, calc and test
WC()->cart->add_to_cart($product->id, 1);
WC()->cart->calculate_totals();
$this->assertEquals('9.00', number_format(WC()->cart->total, 2, '.', ''));
$this->assertEquals('1.00', number_format(WC()->cart->discount_cart, 2, '.', ''));
// Add product to cart x2, calc and test
WC()->cart->add_to_cart($product->id, 1);
WC()->cart->calculate_totals();
$this->assertEquals('19.00', number_format(WC()->cart->total, 2, '.', ''));
$this->assertEquals('1.00', number_format(WC()->cart->discount_cart, 2, '.', ''));
// Add product to cart x3, calc and test
WC()->cart->add_to_cart($product->id, 1);
WC()->cart->calculate_totals();
$this->assertEquals('29.00', number_format(WC()->cart->total, 2, '.', ''));
$this->assertEquals('1.00', number_format(WC()->cart->discount_cart, 2, '.', ''));
// Clean up the cart
WC()->cart->empty_cart();
WC()->cart->remove_coupons();
# Test case 2 #10573
update_post_meta($product->id, '_regular_price', '29.95');
update_post_meta($product->id, '_price', '29.95');
update_post_meta($coupon->id, 'discount_type', 'percent');
update_post_meta($coupon->id, 'coupon_amount', '10');
update_option('woocommerce_prices_include_tax', 'yes');
update_option('woocommerce_calc_taxes', 'yes');
$tax_rate = array('tax_rate_country' => '', 'tax_rate_state' => '', 'tax_rate' => '10.0000', 'tax_rate_name' => 'TAX', 'tax_rate_priority' => '1', 'tax_rate_compound' => '0', 'tax_rate_shipping' => '1', 'tax_rate_order' => '1', 'tax_rate_class' => '');
WC_Tax::_insert_tax_rate($tax_rate);
$product = wc_get_product($product->id);
WC()->cart->add_to_cart($product->id, 1);
WC()->cart->add_discount($coupon->code);
WC()->cart->calculate_totals();
$cart_item = current(WC()->cart->get_cart());
$this->assertEquals('24.51', number_format($cart_item['line_total'], 2, '.', ''));
// Cleanup
$wpdb->query("DELETE FROM {$wpdb->prefix}woocommerce_tax_rates");
$wpdb->query("DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations");
WC()->cart->empty_cart();
WC()->cart->remove_coupons();
update_option('woocommerce_prices_include_tax', 'no');
update_option('woocommerce_calc_taxes', 'no');
// Delete coupon
WC_Helper_Coupon::delete_coupon($coupon->id);
// Clean up product
WC_Helper_Product::delete_product($product->id);
}
开发者ID:coderkevin,项目名称:woocommerce,代码行数:67,代码来源:cart.php
示例9: ywev_get_tax_classes
function ywev_get_tax_classes()
{
if (version_compare(WOOCOMMERCE_VERSION, '2.3', '<')) {
return array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes'))));
} else {
return WC_Tax::get_tax_classes();
}
}
开发者ID:yarwalker,项目名称:ecobyt,代码行数:8,代码来源:functions.php
示例10: set_base_tax_rates
public function set_base_tax_rates($rates, $tax_class)
{
$location = WC_Tax::get_tax_location($tax_class);
if (in_array($tax_class, array('virtual-rate', 'virtual-reduced-rate')) && isset($location[0]) && sizeof($location) === 4 && $location[0] !== WC()->countries->get_base_country()) {
list($country, $state, $postcode, $city) = $location;
$rates = WC_Tax::find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $tax_class));
}
return $rates;
}
开发者ID:ronzeiller,项目名称:woocommerce-germanized,代码行数:9,代码来源:class-wc-gzd-virtual-vat-helper.php
示例11: widget
/**
* Output widget.
*
* @see WP_Widget
*
* @param array $args
* @param array $instance
*/
public function widget($args, $instance)
{
global $wp, $wp_the_query;
if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
return;
}
if (!$wp_the_query->post_count) {
return;
}
$min_price = isset($_GET['min_price']) ? esc_attr($_GET['min_price']) : '';
$max_price = isset($_GET['max_price']) ? esc_attr($_GET['max_price']) : '';
wp_enqueue_script('wc-price-slider');
// Find min and max price in current result set
$prices = $this->get_filtered_price();
$min = floor($prices->min_price);
$max = ceil($prices->max_price);
if ($min === $max) {
return;
}
$this->widget_start($args, $instance);
if ('' === get_option('permalink_structure')) {
$form_action = remove_query_arg(array('page', 'paged'), add_query_arg($wp->query_string, '', home_url($wp->request)));
} else {
$form_action = preg_replace('%\\/page/[0-9]+%', '', home_url(trailingslashit($wp->request)));
}
/**
* Adjust max if the store taxes are not displayed how they are stored.
* Min is left alone because the product may not be taxable.
* Kicks in when prices excluding tax are displayed including tax.
*/
if (wc_tax_enabled() && 'incl' === get_option('woocommerce_tax_display_shop') && !wc_prices_include_tax()) {
$tax_classes = array_merge(array(''), WC_Tax::get_tax_classes());
$class_max = $max;
foreach ($tax_classes as $tax_class) {
if ($tax_rates = WC_Tax::get_rates($tax_class)) {
$class_max = $max + WC_Tax::get_tax_total(WC_Tax::calc_exclusive_tax($max, $tax_rates));
}
}
$max = $class_max;
}
echo '<form method="get" action="' . esc_url($form_action) . '">
<div class="price_slider_wrapper">
<div class="price_slider" style="display:none;"></div>
<div class="price_slider_amount">
<input type="text" id="min_price" name="min_price" value="' . esc_attr($min_price) . '" data-min="' . esc_attr(apply_filters('woocommerce_price_filter_widget_min_amount', $min)) . '" placeholder="' . esc_attr__('Min price', 'woocommerce') . '" />
<input type="text" id="max_price" name="max_price" value="' . esc_attr($max_price) . '" data-max="' . esc_attr(apply_filters('woocommerce_price_filter_widget_max_amount', $max)) . '" placeholder="' . esc_attr__('Max price', 'woocommerce') . '" />
<button type="submit" class="button">' . __('Filter', 'woocommerce') . '</button>
<div class="price_label" style="display:none;">
' . __('Price:', 'woocommerce') . ' <span class="from"></span> — <span class="to"></span>
</div>
' . wc_query_string_form_fields(null, array('min_price', 'max_price'), '', true) . '
<div class="clear"></div>
</div>
</div>
</form>';
$this->widget_end($args);
}
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:65,代码来源:class-wc-widget-price-filter.php
示例12: 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
示例13: tax_classes
public function tax_classes()
{
$tax_classes = WC_Tax::get_tax_classes();
$classes_options = array();
if (!empty($tax_classes)) {
foreach ($tax_classes as $class) {
$classes_options[sanitize_title($class)] = esc_html($class);
}
}
return $classes_options;
}
开发者ID:WPprodigy,项目名称:woocommerce-product-fees,代码行数:11,代码来源:class-wcpf-admin-global-settings.php
示例14: tax_rates
/**
* Returns base tax rates for all tax classes
* @return array
*/
public static function tax_rates()
{
$rates = array();
foreach (self::tax_classes() as $class => $label) {
if ($rate = WC_Tax::get_base_tax_rates($class)) {
// WC_Tax returns a assoc array with int as keys = world of pain in js
// possibly change $key to $rate['id']
$rates[$class] = $rate;
}
}
return $rates;
}
开发者ID:rpidanny,项目名称:WooCommerce-POS,代码行数:16,代码来源:class-wc-pos-tax.php
示例15: 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
示例16: calculate_shipping
/**
* calculate_shipping function.
*
* @access public
*
* @param mixed $package
*
* @return void
*/
public function calculate_shipping($package)
{
$products = $package['contents'];
$destination_country = isset($package['destination']['country']) ? $package['destination']['country'] : '';
$destination_state = isset($package['destination']['state']) ? $package['destination']['state'] : '';
$amount = 0.0;
if ($products) {
$amount = $this->calculate_per_seller($products, $destination_country, $destination_state);
}
$tax_rate = $this->tax_status == 'none' ? false : '';
if ($tax_rate === '') {
$rates = WC_Tax::get_shipping_tax_rates();
$taxRate = reset($rates);
$taxkey = key($rates);
$tax_rates = array();
$shippingTaxes = 0;
$price = $this->calculate_per_seller_prices($products, $destination_country, $destination_state);
//var_dump($price);
// var_dump($rates);
if (!empty($price)) {
foreach ($price as $seller_id => $value) {
//TODO: Check if taxxing from same state;
//var_dump($_product->post->post_author);
$country_obj = new WC_Countries();
$countries = $country_obj->countries;
$states = $country_obj->states;
$selleraddress = dokan_get_seller_address($seller_id, true);
$sellerState = $selleraddress['state'];
$stateCode = array_search(ucfirst(strtolower($sellerState)), $states['US']);
if ($stateCode !== false) {
$sellerState = $stateCode;
}
$location = WC()->customer->get_taxable_address();
$buyerState = $location[1];
if ($buyerState == $sellerState) {
$shippingCost = array_sum($value['addition_price']) + $value['default'] + array_sum($value['qty']) + $value['add_product'] + (isset($value['state_rates']) ? $value['state_rates'] : 0);
$shippingTaxes += $shippingCost * $taxRate['rate'] / 100;
//var_dump($shippingCost, $taxRate);
}
}
}
$tax_rate[$taxkey] = $shippingTaxes;
//var_dump($tax_rate);
}
$rate = array('id' => $this->id, 'label' => $this->title, 'cost' => $amount, 'taxes' => $tax_rate);
// Register the rate
$this->add_rate($rate);
}
开发者ID:nealmattox,项目名称:updatednebrowse,代码行数:57,代码来源:shipping.php
示例17: add_eu_countries_vat_rates
/**
* add_eu_countries_vat_rates.
*
* @version 2.3.10
* @since 2.3.10
*/
function add_eu_countries_vat_rates()
{
if (!isset($_POST['add_eu_countries_vat_rates'])) {
return;
}
if (!is_super_admin() && !is_shop_manager()) {
return;
}
$loop = 0;
foreach (wcj_get_european_union_countries_with_vat() as $country => $rate) {
$tax_rate = array('tax_rate_country' => $country, 'tax_rate' => $rate, 'tax_rate_name' => isset($_POST['wcj_tax_name']) ? $_POST['wcj_tax_name'] : __('VAT', 'woocommerce'), 'tax_rate_priority' => 1, 'tax_rate_compound' => 0, 'tax_rate_shipping' => 1, 'tax_rate_order' => $loop++, 'tax_rate_class' => '');
$tax_rate_id = WC_Tax::_insert_tax_rate($tax_rate);
WC_Tax::_update_tax_rate_postcodes($tax_rate_id, '');
WC_Tax::_update_tax_rate_cities($tax_rate_id, '');
}
}
开发者ID:yarwalker,项目名称:ecobyt,代码行数:22,代码来源:class-wcj-eu-countries-vat-rates-tool.php
示例18: install_standard_rates
public function install_standard_rates()
{
// delete previous inserted standard rates
$tax_rates = $this->get_tax_rates();
foreach ($tax_rates as $tax_rate) {
$tax_rate_name = sprintf("EU VAT (%s)", $tax_rate->tax_rate_country);
if (0 == strpos($tax_rate->tax_rate_name, $tax_rate_name)) {
WC_Tax::_delete_tax_rate($tax_rate->tax_rate_id);
}
}
foreach ($this->tax_rates_data as $key => $value) {
$tax_rate = array('tax_rate_country' => $key, 'tax_rate_state' => '*', 'tax_rate' => $value["standard_rate"], 'tax_rate_name' => sprintf("EU VAT (%s) %s%%", $key, $value["standard_rate"]), 'tax_rate_priority' => 1, 'tax_rate_compound' => 1, 'tax_rate_shipping' => 1, 'tax_rate_class' => '');
$tax_rate_id = WC_Tax::_insert_tax_rate($tax_rate);
WC_Tax::_update_tax_rate_postcodes($tax_rate_id, wc_clean('*'));
WC_Tax::_update_tax_rate_cities($tax_rate_id, wc_clean('*'));
}
}
开发者ID:yarwalker,项目名称:ecobyt,代码行数:17,代码来源:class.yith-tax-rates.php
示例19: import_dummy_tax
/**
* copy of import function: WC_Tax_Rate_Importer->import()
* https://github.com/woothemes/woocommerce/blob/master/includes/admin/importers/class-wc-tax-rate-importer.php
*/
private function import_dummy_tax()
{
// clear tax rate tables
global $wpdb;
$wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates");
$wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations");
$file = WC_POS_PLUGIN_PATH . 'tests/data/sample_tax_rates.csv';
$delimiter = ',';
$loop = 0;
if (($handle = fopen($file, "r")) !== false) {
$header = fgetcsv($handle, 0, $delimiter);
if (10 === sizeof($header)) {
while (($row = fgetcsv($handle, 0, $delimiter)) !== false) {
list($country, $state, $postcode, $city, $rate, $name, $priority, $compound, $shipping, $class) = $row;
$tax_rate = array('tax_rate_country' => $country, 'tax_rate_state' => $state, 'tax_rate' => $rate, 'tax_rate_name' => $name, 'tax_rate_priority' => $priority, 'tax_rate_compound' => $compound ? 1 : 0, 'tax_rate_shipping' => $shipping ? 1 : 0, 'tax_rate_order' => $loop++, 'tax_rate_class' => $class);
$tax_rate_id = WC_Tax::_insert_tax_rate($tax_rate);
WC_Tax::_update_tax_rate_postcodes($tax_rate_id, wc_clean($postcode));
WC_Tax::_update_tax_rate_cities($tax_rate_id, wc_clean($city));
}
}
fclose($handle);
}
}
开发者ID:rpidanny,项目名称:WooCommerce-POS,代码行数:27,代码来源:bootstrap.php
示例20: calc_tax_rate
private function calc_tax_rate($product)
{
static $tax_rates = array();
$item_tax_rates = array();
$compound_tax_rates = 0;
$regular_tax_rates = 0;
if (empty($tax_rates[$product->get_tax_class()])) {
$tax_rates[$product->get_tax_class()] = WC_Tax::get_rates($product->get_tax_class());
}
$item_tax_rates = $tax_rates[$product->get_tax_class()];
$regular_tax_rates = $compound_tax_rates = 0;
foreach ($item_tax_rates as $key => $rate) {
if ($rate['compound'] == 'yes') {
$compound_tax_rates = $compound_tax_rates + $rate['rate'];
} else {
$regular_tax_rates = $regular_tax_rates + $rate['rate'];
}
}
$regular_tax_rate = 1 + $regular_tax_rates / 100;
$compound_tax_rate = 1 + $compound_tax_rates / 100;
$the_rate = 0;
foreach ($item_tax_rates as $key => $rate) {
if (!isset($taxes[$key])) {
$taxes[$key] = 0;
}
$the_rate = $rate['rate'];
// 100;
if ($rate['compound'] == 'yes') {
//$the_price = $price;
// $the_rate = $the_rate / $compound_tax_rate;
} else {
//$the_price = $non_compound_price;
// $the_rate = $the_rate / $regular_tax_rate;
}
}
return $the_rate;
}
开发者ID:jyrkih,项目名称:woocommerce_payment_module,代码行数:37,代码来源:MaksuturvaGatewayWCImpl.php
注:本文中的WC_Tax类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论