本文整理汇总了PHP中WC_Tax::get_rates方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Tax::get_rates方法的具体用法?PHP WC_Tax::get_rates怎么用?PHP WC_Tax::get_rates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Tax
的用法示例。
在下文中一共展示了WC_Tax::get_rates方法的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);
}
}
}
}
}
}
示例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);
}
示例3: get_product_subtotal
/**
* 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
*/
public 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->tax_display_cart == 'excl') {
$row_price = $_product->get_price_excluding_tax($quantity);
$product_subtotal = woocommerce_price($row_price);
if ($this->prices_include_tax && $this->tax_total > 0) {
$product_subtotal .= ' <small class="tax_label">' . $woocommerce->countries->ex_tax_or_vat() . '</small>';
}
} else {
$row_price = $_product->get_price_including_tax($quantity);
$product_subtotal = woocommerce_price($row_price);
if (!$this->prices_include_tax && $this->tax_total > 0) {
$product_subtotal .= ' <small class="tax_label">' . $woocommerce->countries->inc_tax_or_vat() . '</small>';
}
}
// 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);
}
示例4: 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);
}
示例5: test_get_rates
/**
* Get rates.
*/
public function test_get_rates()
{
global $wpdb;
$wpdb->query("DELETE FROM {$wpdb->prefix}woocommerce_tax_rates");
$wpdb->query("DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations");
$customer_location = WC_Tax::get_tax_location();
$tax_rate = array('tax_rate_country' => $customer_location[0], 'tax_rate_state' => '', 'tax_rate' => '20.0000', 'tax_rate_name' => 'VAT', 'tax_rate_priority' => '1', 'tax_rate_compound' => '0', 'tax_rate_shipping' => '1', 'tax_rate_order' => '1', 'tax_rate_class' => '');
$tax_rate_id = WC_Tax::_insert_tax_rate($tax_rate);
$tax_rates = WC_Tax::get_rates();
$this->assertEquals($tax_rates, array($tax_rate_id => array('rate' => '20.0000', 'label' => 'VAT', 'shipping' => 'yes', 'compound' => 'no')));
WC_Tax::_delete_tax_rate($tax_rate_id);
}
示例6: 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);
if (!empty($fee_taxes)) {
// Tax rows - merge the totals we just got
foreach (array_keys($this->taxes) as $key) {
$this->taxes[$key] = (isset($fee_taxes[$key]) ? $fee_taxes[$key] : 0) + (isset($this->taxes[$key]) ? $this->taxes[$key] : 0);
}
}
}
}
}
}
示例7: 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;
}
示例8: get_price_including_tax
/**
* Returns the price (including tax). Uses customer tax rates. Can work for a specific $qty for more accurate taxes.
*
* @param string $price to calculate, left blank to just use get_price()
* @return string
*/
public function get_price_including_tax($qty = 1, $price = '')
{
if ($price === '') {
$price = $this->get_price();
}
if ($this->is_taxable()) {
if (get_option('woocommerce_prices_include_tax') === 'no') {
$tax_rates = WC_Tax::get_rates($this->get_tax_class());
$taxes = WC_Tax::calc_tax($price * $qty, $tax_rates, false);
$tax_amount = WC_Tax::get_tax_total($taxes);
$price = round($price * $qty + $tax_amount, wc_get_price_decimals());
} else {
$tax_rates = WC_Tax::get_rates($this->get_tax_class());
$base_tax_rates = WC_Tax::get_base_tax_rates($this->tax_class);
if (!empty(WC()->customer) && WC()->customer->is_vat_exempt()) {
$base_taxes = WC_Tax::calc_tax($price * $qty, $base_tax_rates, true);
$base_tax_amount = array_sum($base_taxes);
$price = round($price * $qty - $base_tax_amount, wc_get_price_decimals());
/**
* The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations.
* e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes.
* This feature is experimental @since 2.4.7 and may change in the future. Use at your risk.
*/
} elseif ($tax_rates !== $base_tax_rates && apply_filters('woocommerce_adjust_non_base_location_prices', true)) {
$base_taxes = WC_Tax::calc_tax($price * $qty, $base_tax_rates, true);
$modded_taxes = WC_Tax::calc_tax($price * $qty - array_sum($base_taxes), $tax_rates, false);
$price = round($price * $qty - array_sum($base_taxes) + array_sum($modded_taxes), wc_get_price_decimals());
} else {
$price = $price * $qty;
}
}
} else {
$price = $price * $qty;
}
return apply_filters('woocommerce_get_price_including_tax', $price, $qty, $this);
}
示例9: get_tax_rate
/**
* Get the tax rates/percentages for a given tax class
* @param string $tax_class tax class slug
* @return string $tax_rates imploded list of tax rates
*/
public function get_tax_rate($tax_class, $line_total, $line_tax)
{
if (version_compare(WOOCOMMERCE_VERSION, '2.1') >= 0) {
// WC 2.1 or newer is used
if ($line_tax == 0) {
return '-';
// no need to determine tax rate...
}
// if (empty($tax_class))
// $tax_class = 'standard';// does not appear to work anymore - get_rates does accept an empty tax_class though!
$tax = new WC_Tax();
$taxes = $tax->get_rates($tax_class);
$tax_rates = array();
foreach ($taxes as $tax) {
$tax_rates[$tax['label']] = round($tax['rate'], 2) . '%';
}
if (empty($tax_rates)) {
// one last try: manually calculate
if ($line_total != 0) {
$tax_rates[] = round($line_tax / $line_total * 100, 1) . '%';
} else {
$tax_rates[] = '-';
}
}
$tax_rates = implode(' ,', $tax_rates);
} else {
// Backwards compatibility: calculate tax from line items
if ($line_total != 0) {
$tax_rates = round($line_tax / $line_total * 100, 1) . '%';
} else {
$tax_rates = '-';
}
}
return $tax_rates;
}
示例10: get_variation_prices
/**
* Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
*
* Can be filtered by plugins which modify costs, but otherwise will include the raw meta costs unlike get_price() which runs costs through the woocommerce_get_price filter.
* This is to ensure modified prices are not cached, unless intended.
*
* @param bool $display Are prices for display? If so, taxes will be calculated.
* @return array() Array of RAW prices, regular prices, and sale prices with keys set to variation ID.
*/
public function get_variation_prices($display = false)
{
global $wp_filter;
/**
* Transient name for storing prices for this product.
* Max transient length is 45, -10 for get_transient_version.
* @var string
* @since 2.5.0 a single transient is used per product for all prices, rather than many transients per product.
*/
$transient_name = 'wc_var_prices' . $this->id . '_' . WC_Cache_Helper::get_transient_version('product');
/**
* Create unique cache key based on the tax location (affects displayed/cached prices), product version and active price filters.
* DEVELOPERS should filter this hash if offering conditonal pricing to keep it unique.
* @var string
*/
if ($display) {
$price_hash = array(true, WC_Tax::get_rates(), get_option('woocommerce_tax_display_shop'));
} else {
$price_hash = array(false);
}
foreach ($wp_filter as $key => $val) {
if (in_array($key, array('woocommerce_variation_prices_price', 'woocommerce_variation_prices_regular_price', 'woocommerce_variation_prices_sale_price'))) {
$price_hash[$key] = $val;
}
}
$price_hash = md5(json_encode(apply_filters('woocommerce_get_variation_prices_hash', $price_hash, $this, $display)));
// If the value has already been generated, return it now
if (!empty($this->prices_array[$price_hash])) {
return $this->prices_array[$price_hash];
}
// Get value of transient
$this->prices_array = array_filter((array) get_transient($transient_name));
// If the prices are not stored for this hash, generate them
if (empty($this->prices_array[$price_hash])) {
$prices = array();
$regular_prices = array();
$sale_prices = array();
$variation_ids = $this->get_children(true);
foreach ($variation_ids as $variation_id) {
if ($variation = $this->get_child($variation_id)) {
$price = apply_filters('woocommerce_variation_prices_price', $variation->price, $variation, $this);
$regular_price = apply_filters('woocommerce_variation_prices_regular_price', $variation->regular_price, $variation, $this);
$sale_price = apply_filters('woocommerce_variation_prices_sale_price', $variation->sale_price, $variation, $this);
// If sale price does not equal price, the product is not yet on sale
if ($sale_price === $regular_price || $sale_price !== $price) {
$sale_price = $regular_price;
}
// If we are getting prices for display, we need to account for taxes
if ($display) {
if ('incl' === get_option('woocommerce_tax_display_shop')) {
$price = '' === $price ? '' : $variation->get_price_including_tax(1, $price);
$regular_price = '' === $regular_price ? '' : $variation->get_price_including_tax(1, $regular_price);
$sale_price = '' === $sale_price ? '' : $variation->get_price_including_tax(1, $sale_price);
} else {
$price = '' === $price ? '' : $variation->get_price_excluding_tax(1, $price);
$regular_price = '' === $regular_price ? '' : $variation->get_price_excluding_tax(1, $regular_price);
$sale_price = '' === $sale_price ? '' : $variation->get_price_excluding_tax(1, $sale_price);
}
}
$prices[$variation_id] = $price;
$regular_prices[$variation_id] = $regular_price;
$sale_prices[$variation_id] = $sale_price;
}
}
asort($prices);
asort($regular_prices);
asort($sale_prices);
$this->prices_array[$price_hash] = array('price' => $prices, 'regular_price' => $regular_prices, 'sale_price' => $sale_prices);
set_transient($transient_name, $this->prices_array, DAY_IN_SECONDS * 30);
}
/**
* Give plugins one last chance to filter the variation prices array which is being returned.
*/
return $this->prices_array[$price_hash] = apply_filters('woocommerce_variation_prices', $this->prices_array[$price_hash], $this, $display);
}
示例11: round
/**
* Returns the price (including tax). Uses customer tax rates. Can work for a specific $qty for more accurate taxes.
*
* @access public
* @return string
*/
function get_price_including_tax($qty = 1)
{
global $woocommerce;
$_tax = new WC_Tax();
$price = $this->get_price();
if ($this->is_taxable()) {
if (get_option('woocommerce_prices_include_tax') == 'no') {
$tax_rates = $_tax->get_rates($this->get_tax_class());
$taxes = $_tax->calc_tax($price * $qty, $tax_rates, false);
$tax_amount = $_tax->get_tax_total($taxes);
$price = round($price * $qty + $tax_amount, 2);
} else {
$tax_rates = $_tax->get_rates($this->get_tax_class());
$base_tax_rates = $_tax->get_shop_base_rate($this->tax_class);
if ($woocommerce->customer->is_vat_exempt()) {
$base_taxes = $_tax->calc_tax($price * $qty, $base_tax_rates, true);
$base_tax_amount = array_sum($base_taxes);
$price = round($price * $qty - $base_tax_amount, 2);
} elseif ($tax_rates !== $base_tax_rates) {
$base_taxes = $_tax->calc_tax($price * $qty, $base_tax_rates, true, true);
$modded_taxes = $_tax->calc_tax($price * $qty - array_sum($base_taxes), $tax_rates, false);
$price = round($price * $qty - array_sum($base_taxes) + array_sum($modded_taxes), 2);
} else {
$price = $price * $qty;
}
}
} else {
$price = $price * $qty;
}
return apply_filters('woocommerce_get_price_including_tax', $price, $qty, $this);
}
示例12: 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;
}
}
}
}
示例13: get_tax_info
/**
* Gets a product's tax description (if is taxable)
*
* @return mixed string if is taxable else returns false
*/
public function get_tax_info()
{
$_tax = new WC_Tax();
$tax_notice = false;
if ($this->is_taxable()) {
$tax_display_mode = get_option('woocommerce_tax_display_shop');
$tax_rates = $_tax->get_rates($this->get_tax_class());
if (!empty($tax_rates)) {
$tax_rates = array_values($tax_rates);
// If is variable or is virtual vat exception dont show exact tax rate
if ($this->is_virtual_vat_exception() || $this->is_type('variable')) {
$tax_notice = $tax_display_mode == 'incl' && !WC()->customer->is_vat_exempt() ? __('incl. VAT', 'woocommerce-germanized') : __('excl. VAT', 'woocommerce-germanized');
} else {
$tax_notice = $tax_display_mode == 'incl' && !WC()->customer->is_vat_exempt() ? sprintf(__('incl. %s%% VAT', 'woocommerce-germanized'), wc_gzd_format_tax_rate_percentage($tax_rates[0]['rate'])) : sprintf(__('excl. %s%% VAT', 'woocommerce-germanized'), wc_gzd_format_tax_rate_percentage($tax_rates[0]['rate']));
}
}
}
return apply_filters('woocommerce_gzd_product_tax_info', $tax_notice, $this);
}
示例14: price_filter_meta_query
/**
* Return a meta query for filtering by price.
* @return array
*/
private function price_filter_meta_query()
{
if (isset($_GET['max_price']) || isset($_GET['min_price'])) {
$min = isset($_GET['min_price']) ? floatval($_GET['min_price']) : 0;
$max = isset($_GET['max_price']) ? floatval($_GET['max_price']) : 9999999999.0;
/**
* Adjust if the store taxes are not displayed how they are stored.
* Max is left alone because the filter was already increased.
* 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_min = $min;
foreach ($tax_classes as $tax_class) {
if ($tax_rates = WC_Tax::get_rates($tax_class)) {
$class_min = $min - WC_Tax::get_tax_total(WC_Tax::calc_exclusive_tax($min, $tax_rates));
}
}
$min = $class_min;
}
return array('key' => '_price', 'value' => array($min, $max), 'compare' => 'BETWEEN', 'type' => 'DECIMAL', 'price_filter' => true);
}
return array();
}
示例15: set_fee
/**
* Sets fee for a specific gateway
*
* @param object $gateway
*/
public function set_fee($gateway)
{
$is_taxable = $gateway->get_option('fee_is_taxable', 'no') == 'no' ? false : true;
$fee = $gateway->get_option('fee');
if ($is_taxable) {
$tax_rates = WC_Tax::get_rates();
$fee_taxes = WC_Tax::calc_tax($fee, $tax_rates, true);
$fee = $fee - array_sum($fee_taxes);
}
WC()->cart->add_fee(__('Payment charge', 'woocommerce-germanized'), $fee, $is_taxable);
}