本文整理汇总了PHP中WC_Tax::get_tax_classes方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Tax::get_tax_classes方法的具体用法?PHP WC_Tax::get_tax_classes怎么用?PHP WC_Tax::get_tax_classes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Tax
的用法示例。
在下文中一共展示了WC_Tax::get_tax_classes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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();
}
}
示例3: 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);
}
示例4: 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;
}
示例5: tax_classes
/**
* Returns all tax classes, class => label
* @return array
*/
public static function tax_classes()
{
$classes = array('' => __('Standard', 'woocommerce'));
// get_tax_classes method introduced in WC 2.3
if (method_exists('WC_Tax', 'get_tax_classes')) {
$labels = WC_Tax::get_tax_classes();
} else {
$labels = array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes'))));
}
foreach ($labels as $label) {
$classes[sanitize_title($label)] = $label;
}
return $classes;
}
示例6: price_filter
/**
* Price Filter post filter.
*
* @param array $filtered_posts
* @return array
*/
public function price_filter($filtered_posts = array())
{
global $wpdb;
if (isset($_GET['max_price']) || isset($_GET['min_price'])) {
$matched_products = array();
$min = isset($_GET['min_price']) ? floatval($_GET['min_price']) : 0;
$max = isset($_GET['max_price']) ? floatval($_GET['max_price']) : 9999999999;
// If displaying prices in the shop including taxes, but prices don't include taxes..
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());
foreach ($tax_classes as $tax_class) {
$tax_rates = WC_Tax::get_rates($tax_class);
$min_class = $min - WC_Tax::get_tax_total(WC_Tax::calc_inclusive_tax($min, $tax_rates));
$max_class = $max - WC_Tax::get_tax_total(WC_Tax::calc_inclusive_tax($max, $tax_rates));
$matched_products_query = apply_filters('woocommerce_price_filter_results', $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\tSELECT DISTINCT ID, post_parent, post_type FROM {$wpdb->posts}\n\t\t\t\t\t\tINNER JOIN {$wpdb->postmeta} pm1 ON ID = pm1.post_id\n\t\t\t\t\t\tINNER JOIN {$wpdb->postmeta} pm2 ON ID = pm2.post_id\n\t\t\t\t\t\tWHERE post_type IN ( 'product', 'product_variation' )\n\t\t\t\t\t\tAND post_status = 'publish'\n\t\t\t\t\t\tAND pm1.meta_key IN ('" . implode("','", array_map('esc_sql', apply_filters('woocommerce_price_filter_meta_keys', array('_price')))) . "')\n\t\t\t\t\t\tAND pm1.meta_value BETWEEN %f AND %f\n\t\t\t\t\t\tAND pm2.meta_key = '_tax_class'\n\t\t\t\t\t\tAND pm2.meta_value = %s\n\t\t\t\t\t", $min_class, $max_class, sanitize_title($tax_class)), OBJECT_K), $min_class, $max_class);
if ($matched_products_query) {
foreach ($matched_products_query as $product) {
if ($product->post_type == 'product') {
$matched_products[] = $product->ID;
}
if ($product->post_parent > 0) {
$matched_products[] = $product->post_parent;
}
}
}
}
} else {
$matched_products_query = apply_filters('woocommerce_price_filter_results', $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\tSELECT DISTINCT ID, post_parent, post_type FROM {$wpdb->posts}\n\t\t\t\t\tINNER JOIN {$wpdb->postmeta} pm1 ON ID = pm1.post_id\n\t\t\t\t\tWHERE post_type IN ( 'product', 'product_variation' )\n\t\t\t\t\tAND post_status = 'publish'\n\t\t\t\t\tAND pm1.meta_key IN ('" . implode("','", array_map('esc_sql', apply_filters('woocommerce_price_filter_meta_keys', array('_price')))) . "')\n\t\t\t\t\tAND pm1.meta_value BETWEEN %d AND %d\n\t\t\t\t", $min, $max), OBJECT_K), $min, $max);
if ($matched_products_query) {
foreach ($matched_products_query as $product) {
if ($product->post_type == 'product') {
$matched_products[] = $product->ID;
}
if ($product->post_parent > 0) {
$matched_products[] = $product->post_parent;
}
}
}
}
$matched_products = array_unique($matched_products);
// Filter the id's
if (0 === sizeof($filtered_posts)) {
$filtered_posts = $matched_products;
} else {
$filtered_posts = array_intersect($filtered_posts, $matched_products);
}
$filtered_posts[] = 0;
}
return (array) $filtered_posts;
}
示例7: get_collection_params
/**
* Get the query params for collections of attachments.
*
* @return array
*/
public function get_collection_params()
{
$params = parent::get_collection_params();
$params['slug'] = array('description' => __('Limit result set to products with a specific slug.', 'woocommerce'), 'type' => 'string', 'validate_callback' => 'rest_validate_request_arg');
$params['status'] = array('default' => 'any', 'description' => __('Limit result set to products assigned a specific status.', 'woocommerce'), 'type' => 'string', 'enum' => array_merge(array('any'), array_keys(get_post_statuses())), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg');
$params['type'] = array('description' => __('Limit result set to products assigned a specific type.', 'woocommerce'), 'type' => 'string', 'enum' => array_keys(wc_get_product_types()), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg');
$params['sku'] = array('description' => __('Limit result set to products with a specific SKU.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
$params['featured'] = array('description' => __('Limit result set to featured products.', 'woocommerce'), 'type' => 'boolean', 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg');
$params['category'] = array('description' => __('Limit result set to products assigned a specific category ID.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg');
$params['tag'] = array('description' => __('Limit result set to products assigned a specific tag ID.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg');
$params['shipping_class'] = array('description' => __('Limit result set to products assigned a specific shipping class ID.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg');
$params['attribute'] = array('description' => __('Limit result set to products with a specific attribute.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
$params['attribute_term'] = array('description' => __('Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg');
if (wc_tax_enabled()) {
$params['tax_class'] = array('description' => __('Limit result set to products with a specific tax class.', 'woocommerce'), 'type' => 'string', 'enum' => array_map('sanitize_title', array_merge(array('standard'), WC_Tax::get_tax_classes())), 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
}
$params['in_stock'] = array('description' => __('Limit result set to products in stock or out of stock.', 'woocommerce'), 'type' => 'boolean', 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg');
$params['on_sale'] = array('description' => __('Limit result set to products on sale.', 'woocommerce'), 'type' => 'boolean', 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg');
$params['min_price'] = array('description' => __('Limit result set to products based on a minimum price.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
$params['max_price'] = array('description' => __('Limit result set to products based on a maximum price.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
return $params;
}
示例8: wc_get_product_tax_class_options
/**
* Get product tax class options.
*
* @since 2.7.0
* @return array
*/
function wc_get_product_tax_class_options()
{
$tax_classes = WC_Tax::get_tax_classes();
$tax_class_options = array();
$tax_class_options[''] = __('Standard', 'woocommerce');
if (!empty($tax_classes)) {
foreach ($tax_classes as $class) {
$tax_class_options[sanitize_title($class)] = $class;
}
}
return $tax_class_options;
}
示例9: add_fees_settings
/**
* add_fees_settings.
*
* @version 2.3.0
*/
function add_fees_settings($settings)
{
// Gateway's Extra Fees
$settings[] = array('title' => __('Payment Gateways Fees and Discounts Options', 'woocommerce-jetpack'), 'type' => 'title', 'desc' => __('This section lets you set extra fees for payment gateways.', 'woocommerce-jetpack'), 'id' => 'wcj_payment_gateways_fees_options');
//$available_gateways = WC()->payment_gateways->payment_gateways();
global $woocommerce;
$available_gateways = $woocommerce->payment_gateways->payment_gateways();
//$available_gateways = WC()->payment_gateways();
foreach ($available_gateways as $key => $gateway) {
/*echo '<h5>' . $gateway->title . '</h5>';
if ( $gateway->is_available() )
echo '<strong style="color: green;">' . __( 'Available', 'woocommerce-jetpack' ) . '</strong>';
else
echo '<strong style="color: red;">' . __( 'Not available', 'woocommerce-jetpack' ) . '</strong>';*/
$settings = array_merge($settings, array(array('title' => $gateway->title, 'desc' => __('Fee (or discount) title to show to customer.', 'woocommerce-jetpack'), 'desc_tip' => __('Leave blank to disable.', 'woocommerce-jetpack'), 'id' => 'wcj_gateways_fees_text_' . $key, 'default' => '', 'type' => 'text'), array('title' => '', 'desc' => __('Fee (or discount) type.', 'woocommerce-jetpack'), 'desc_tip' => __('Percent or fixed value.', 'woocommerce-jetpack'), 'id' => 'wcj_gateways_fees_type_' . $key, 'default' => 'fixed', 'type' => 'select', 'options' => array('fixed' => __('Fixed', 'woocommerce-jetpack'), 'percent' => __('Percent', 'woocommerce-jetpack'))), array('title' => '', 'desc' => __('Fee (or discount) value.', 'woocommerce-jetpack'), 'desc_tip' => __('The value. For discount enter a negative number.', 'woocommerce-jetpack'), 'id' => 'wcj_gateways_fees_value_' . $key, 'default' => 0, 'type' => 'number', 'custom_attributes' => array('step' => '0.01')), array('title' => '', 'desc' => __('Minimum cart amount for adding the fee (or discount).', 'woocommerce-jetpack'), 'desc_tip' => __('Set 0 to disable.', 'woocommerce-jetpack'), 'id' => 'wcj_gateways_fees_min_cart_amount_' . $key, 'default' => 0, 'type' => 'number', 'custom_attributes' => array('step' => '0.01', 'min' => '0')), array('title' => '', 'desc' => __('Maximum cart amount for adding the fee (or discount).', 'woocommerce-jetpack'), 'desc_tip' => __('Set 0 to disable.', 'woocommerce-jetpack'), 'id' => 'wcj_gateways_fees_max_cart_amount_' . $key, 'default' => 0, 'type' => 'number', 'custom_attributes' => array('step' => '0.01', 'min' => '0')), array('title' => '', 'desc' => __('Round the fee (or discount) value before adding to the cart.', 'woocommerce-jetpack'), 'id' => 'wcj_gateways_fees_round_' . $key, 'default' => 'no', 'type' => 'checkbox'), array('title' => '', 'desc' => __('If rounding is enabled, set precision here.', 'woocommerce-jetpack'), 'id' => 'wcj_gateways_fees_round_precision_' . $key, 'default' => 0, 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0')), array('title' => '', 'desc' => __('Is taxable?', 'woocommerce-jetpack'), 'id' => 'wcj_gateways_fees_is_taxable_' . $key, 'default' => 'no', 'type' => 'checkbox'), array('title' => '', 'desc' => __('Tax Class (only if Taxable selected).', 'woocommerce-jetpack'), 'id' => 'wcj_gateways_fees_tax_class_id_' . $key, 'default' => '', 'type' => 'select', 'options' => array_merge(array(__('Standard Rate', 'woocommerce-jetpack')), WC_Tax::get_tax_classes()))));
}
$settings[] = array('type' => 'sectionend', 'id' => 'wcj_payment_gateways_fees_options');
return $settings;
}
示例10: output_variations
/**
* Show options for the variable product type
*/
public static function output_variations()
{
global $post;
$attributes = maybe_unserialize(get_post_meta($post->ID, '_product_attributes', true));
// See if any are set
$variation_attribute_found = false;
if ($attributes) {
foreach ($attributes as $attribute) {
if (isset($attribute['is_variation'])) {
$variation_attribute_found = true;
break;
}
}
}
// Get tax classes
$tax_classes = WC_Tax::get_tax_classes();
$tax_class_options = array();
$tax_class_options[''] = __('Standard', 'woocommerce');
if ($tax_classes) {
foreach ($tax_classes as $class) {
$tax_class_options[sanitize_title($class)] = esc_attr($class);
}
}
$backorder_options = array('no' => __('Do not allow', 'woocommerce'), 'notify' => __('Allow, but notify customer', 'woocommerce'), 'yes' => __('Allow', 'woocommerce'));
$stock_status_options = array('instock' => __('In stock', 'woocommerce'), 'outofstock' => __('Out of stock', 'woocommerce'));
?>
<div id="variable_product_options" class="panel wc-metaboxes-wrapper"><div id="variable_product_options_inner">
<?php
if (!$variation_attribute_found) {
?>
<div id="message" class="inline woocommerce-message">
<p><?php
_e('Before adding variations, add and save some attributes on the <strong>Attributes</strong> tab.', 'woocommerce');
?>
</p>
<p class="submit"><a class="button-primary" href="<?php
echo esc_url(apply_filters('woocommerce_docs_url', 'http://docs.woothemes.com/document/variable-product/', 'product-variations'));
?>
" target="_blank"><?php
_e('Learn more', 'woocommerce');
?>
</a></p>
</div>
<?php
} else {
?>
<p class="toolbar">
<a href="#" class="close_all"><?php
_e('Close all', 'woocommerce');
?>
</a><a href="#" class="expand_all"><?php
_e('Expand all', 'woocommerce');
?>
</a>
<select id="field_to_edit">
<option value=""><?php
_e('Choose a field to bulk edit…', 'woocommerce');
?>
</option>
<optgroup label="<?php
esc_attr_e('Status', 'woocommerce');
?>
">
<option value="toggle_enabled"><?php
_e('Toggle "Enabled"', 'woocommerce');
?>
</option>
<option value="toggle_downloadable"><?php
_e('Toggle "Downloadable"', 'woocommerce');
?>
</option>
<option value="toggle_virtual"><?php
_e('Toggle "Virtual"', 'woocommerce');
?>
</option>
<option value="delete_all"><?php
_e('Delete all variations', 'woocommerce');
?>
</option>
</optgroup>
<optgroup label="<?php
esc_attr_e('Pricing', 'woocommerce');
?>
">
<option value="variable_regular_price"><?php
_e('Prices', 'woocommerce');
?>
</option>
<option value="variable_regular_price_increase"><?php
_e('Prices increase by (fixed amount or %)', 'woocommerce');
?>
</option>
//.........这里部分代码省略.........
示例11: get_current_tax_class
/**
* Get tax class being edited
* @return string
*/
private function get_current_tax_class()
{
global $current_section;
$tax_classes = WC_Tax::get_tax_classes();
$current_class = '';
foreach ($tax_classes as $class) {
if (sanitize_title($class) == $current_section) {
$current_class = $class;
}
}
return $current_class;
}
示例12: test_get_tax_classes
/**
* Test getting the tax classes.
*/
public function test_get_tax_classes()
{
$tax_classes = WC_Tax::get_tax_classes();
$this->assertEquals($tax_classes, array('Reduced rate', 'Zero rate'));
}
示例13: 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_product_invalid_tax_class', __('Invalid tax class', 'woocommerce'));
}
$this->_data['tax_class'] = $value;
}
示例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;
// If displaying prices in the shop including taxes, but prices don't include taxes..
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());
foreach ($tax_classes as $tax_class) {
$tax_rates = WC_Tax::get_rates($tax_class);
$class_min = $min - WC_Tax::get_tax_total(WC_Tax::calc_inclusive_tax($min, $tax_rates));
$class_max = $max - WC_Tax::get_tax_total(WC_Tax::calc_inclusive_tax($max, $tax_rates));
if ($class_min < $min) {
$min = $class_min;
}
if ($class_max > $max) {
$max = $class_max;
}
}
}
return array('key' => '_price', 'value' => array($min, $max), 'compare' => 'BETWEEN', 'type' => 'DECIMAL', 'price_filter' => true);
}
return array();
}
示例15: 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;
$shipping_tax_total = 0;
$taxes = array();
$shipping_taxes = array();
$tax_based_on = get_option('woocommerce_tax_based_on');
// If is_vat_exempt is 'yes', or wc_tax_enabled is false, return and do nothing.
if ('yes' === $this->is_vat_exempt || !wc_tax_enabled()) {
return false;
}
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);
}
}
}
// Calc taxes for shipping
foreach ($this->get_shipping_methods() as $item_id => $item) {
$shipping_tax_class = get_option('woocommerce_shipping_tax_class');
// Inherit tax class from items
if ('' === $shipping_tax_class) {
$tax_classes = WC_Tax::get_tax_classes();
foreach ($tax_classes as $tax_class) {
$tax_class = sanitize_title($tax_class);
if (in_array($tax_class, $found_tax_classes)) {
$tax_rates = WC_Tax::find_shipping_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $tax_class));
break;
}
}
} else {
$tax_rates = WC_Tax::find_shipping_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => 'standard' === $shipping_tax_class ? '' : $shipping_tax_class));
}
$line_taxes = WC_Tax::calc_tax($item['cost'], $tax_rates, false);
$line_tax = max(0, array_sum($line_taxes));
$shipping_tax_total += $line_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));
// Sum the item taxes
foreach (array_keys($shipping_taxes + $line_taxes) as $key) {
$shipping_taxes[$key] = (isset($line_taxes[$key]) ? $line_taxes[$key] : 0) + (isset($shipping_taxes[$key]) ? $shipping_taxes[$key] : 0);
}
}
// 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;
}