• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / WC_Order_Item_Fee::calculate_taxes() – Calculate item taxes.

You appear to be a bot. Output may be restricted

Description

Calculate item taxes.

Usage

$bool = WC_Order_Item_Fee::calculate_taxes( $calculate_tax_for );

Parameters

$calculate_tax_for
( array ) optional – Location data to get taxes for. Required.

Returns

bool True if taxes were calculated.

Source

File name: woocommerce/includes/class-wc-order-item-fee.php
Lines:

1 to 36 of 36
  public function calculate_taxes( $calculate_tax_for = array() ) {
    if ( ! isset( $calculate_tax_for['country'], $calculate_tax_for['state'], $calculate_tax_for['postcode'], $calculate_tax_for['city'] ) ) {
      return false;
    }
    // Use regular calculation unless the fee is negative.
    if ( 0 <= $this->get_total() ) {
      return parent::calculate_taxes( $calculate_tax_for );
    }

    if ( wc_tax_enabled() && $this->get_order() ) {
      // Apportion taxes to order items, shipping, and fees.
      $order           = $this->get_order();
      $tax_class_costs = $this->get_tax_class_costs( $order );
      $total_costs     = array_sum( $tax_class_costs );
      $discount_taxes  = array();
      if ( $total_costs ) {
        foreach ( $tax_class_costs as $tax_class => $tax_class_cost ) {
          if ( 'non-taxable' === $tax_class ) {
            continue;
          }
          $proportion                     = $tax_class_cost / $total_costs;
          $cart_discount_proportion       = $this->get_total() * $proportion;
          $calculate_tax_for['tax_class'] = $tax_class;
          $tax_rates                      = WC_Tax::find_rates( $calculate_tax_for );
          $discount_taxes                 = wc_array_merge_recursive_numeric( $discount_taxes, WC_Tax::calc_tax( $cart_discount_proportion, $tax_rates ) );
        }
      }
      $this->set_taxes( array( 'total' => $discount_taxes ) );
    } else {
      $this->set_taxes( false );
    }

    do_action( 'woocommerce_order_item_fee_after_calculate_taxes', $this, $calculate_tax_for );

    return true;
  }
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 21st August 2020

Primary Sidebar

Information

Function name: WC_Order_Item_Fee::calculate_taxes
Class ref: WC_Order_Item_Fee
Plugin ref: WooCommerce
Version: 4.8.0
Sourcefile: includes/class-wc-order-item-fee.php
File ref: includes/class-wc-order-item-fee.php
Deprecated?: No
API Letters: C,F,I,O,W

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites