Split Order Subtotal Amount into different tax brackets
-
Hi!
I would like to have a report with the “Order Subtotal Amount” split into my two tax brackets. Like “Order Subtotal Amount 25%” and “Order Subtotal Amount 15%”, is it possible? I found out how to get the total tax amount split up but not the subtotal amount for each.
Thanks in advance ??
-
hi
please, add 2 fields using this way https://docs.algolplus.com/algol_order_export/fields/
inside the function – you should use code
return round($order->get_subtotal() * 0.25,2);
Hi again, thanks for fast reply!
Tried it returned: 0
I see you calculate subtotal with 0.25? I dont know why.
Since I have an order of 498 inc tax, where one item is 156.52 + tax 15% = 23.48, and another product at 199.2 with tax 25% at 49.8, and shipping 55.2 + 13.8 in tax.
I want to collect all values which belong to 25% tax in one column before tax, and another with 15% tax before tax, since thats the two I need.
I dont understand how that return will give me that.
Can one item have 2 different taxes?
Please, edit order and make screenshot of section “Items” only . You can blur item names.
Products either have 15% or 25% VAT/TAX, and its 25% VAT/TAX on shipping/transport.
So an order can have both type of products + shipping.
See https://snipboard.io/cwoe1q.jpg its in norwegian.
So according to your screenshot — you need 2 columns
subtotal_MVA = 49.80+13.80
subtotal_reduced_MVA = 11.74correct ?
1. add following code to functions.php
2. check tax labels in line #2 !
3. go back to export
4. open >Setup Fields>Others
5. ?drag new fields to export, you need “XXX Base Amount”// Extra columns for vat class WOE_add_product_shipping_taxes{ var $taxes = array("Redusert MVA","MVA"); //EDIT tax labels (as you see the inside the section "order items" )! function __construct() { add_filter('woe_get_order_fields', array($this,'add_order_fields'), 10, 1); add_filter('woe_get_order_product_fields', array($this,'add_product_fields'), 10, 2); add_filter('woe_fetch_order', array($this,'fill_shipping_and_total_taxes'), 10, 2); add_filter('woe_fetch_order_product',array($this,'fill_product_taxes'), 10, 5); } function add_order_fields($fields) { global $wpdb; foreach($this->taxes as $tax) { $fields['shipping_tax_amount_'.$tax] = array('label'=>"Shipping $tax Amount",'checked' => 1, 'segment'=>'cart','colname'=>"Shipping $tax Amount", 'format'=>'money'); $fields['shipping_tax_percentage_'.$tax] = array('label'=>"Shipping $tax Percentage",'checked' => 1, 'segment'=>'cart','colname'=>"Shipping $tax Percentage", 'format'=>'number'); $fields['total_tax_amount_'.$tax] = array('label'=>"Total $tax Amount",'checked' => 1, 'segment'=>'cart','colname'=>"Total $tax Amount", 'format'=>'money'); $fields['total_tax_percentage_'.$tax] = array('label'=>"Total $tax Percentage",'checked' => 1, 'segment'=>'cart','colname'=>"Total $tax Percentage", 'format'=>'number'); $fields['tax_plus_base_amount_'.$tax] = array('label'=>"Total $tax Amount (+Base Amount)",'checked' => 1, 'segment'=>'cart','colname'=>"Total $tax Amount(+Base Amount)", 'format'=>'money'); $fields['base_amount_'.$tax] = array('label'=>"$tax Base Amount",'checked' => 1, 'segment'=>'cart','colname'=>"$tax Base Amount", 'format'=>'money'); } return $fields; } function add_product_fields($fields,$format) { global $wpdb; foreach($this->taxes as $tax) { $fields['tax_amount_'.$tax] = array('label'=>"Product $tax Amount",'checked' => 1, 'segment'=>'cart','colname'=>"Product $tax Amount", 'format'=>'money'); $fields['tax_percentage_'.$tax] = array('label'=>"Product $tax Percentage",'checked' => 1, 'segment'=>'cart','colname'=>"Product $tax Percentage", 'format'=>'number'); } return $fields; } function fill_shipping_and_total_taxes($row, $order ) { $shipping_taxes = $shipping_tax_rates = array(); $total_taxes = $total_tax_rates = array(); $order_taxes = $order->get_taxes(); $base_amount = array(); foreach($order->get_items('shipping') as $shipping) { $tax_data = $shipping->get_taxes(); foreach($order_taxes as $tax_item) { $tax_item_id = $tax_item->get_rate_id(); if(!isset( $tax_data['total'][ $tax_item_id ] ) ) continue; $label = $tax_item->get_label() ; $shipping_taxes[$label] = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : 0; $shipping_tax_rates[$label] = $shipping->get_total()>0 ? round($shipping_taxes[$label]/$shipping->get_total() * 100) : 0; } } foreach($order->get_items( array('shipping','fee','line_item')) as $item) { $tax_data = $item->get_taxes(); foreach($order_taxes as $tax_item) { $tax_item_id = $tax_item->get_rate_id(); if(!isset( $tax_data['total'][ $tax_item_id ] ) ) continue; $label = $tax_item->get_label() ; if(!isset($base_amount[$label])) $base_amount[$label] = 0; $base_amount[$label] += $item->get_total(); } } foreach($order_taxes as $tax_item) { $label = $tax_item->get_label() ; $total_taxes[$label] = $tax_item->get_tax_total(); $total_tax_rates[$label] = $tax_item->get_rate_percent(); } foreach($this->taxes as $tax) { if( isset($row['shipping_tax_amount_'.$tax]) ) $row['shipping_tax_amount_'.$tax] = wc_round_tax_total($this->find_tax_by_label($shipping_taxes,$tax)); if( isset($row['shipping_tax_percentage_'.$tax]) ) $row['shipping_tax_percentage_'.$tax] = $this->find_tax_by_label($shipping_tax_rates,$tax); if( isset($row['total_tax_amount_'.$tax]) ) $row['total_tax_amount_'.$tax] = wc_round_tax_total($this->find_tax_by_label($total_taxes,$tax)); if( isset($row['total_tax_percentage_'.$tax]) ) $row['total_tax_percentage_'.$tax] = $this->find_tax_by_label($total_tax_rates,$tax); if( isset($row['tax_plus_base_amount_'.$tax]) ) $row['tax_plus_base_amount_'.$tax] = wc_round_tax_total($this->find_tax_by_label($total_taxes,$tax) + $this->find_tax_by_label($base_amount,$tax) ); if( isset($row['base_amount_'.$tax]) ) $row['base_amount_'.$tax] = wc_round_tax_total( $this->find_tax_by_label($base_amount,$tax) ); } return $row; } function fill_product_taxes($row, $order, $item, $product, $item_meta) { $product_taxes = $product_tax_rates = array(); $order_taxes = $order->get_taxes(); $tax_data = $item->get_taxes(); foreach($order_taxes as $tax_item) { $tax_item_id = $tax_item->get_rate_id(); if(!isset( $tax_data['total'][ $tax_item_id ] ) ) continue; $label = $tax_item->get_label() ; $product_taxes[$label] = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : 0; $product_tax_rates[$label] = $item->get_total()>0 ? round($product_taxes[$label]/$item->get_total() * 100) : 0; } foreach($this->taxes as $tax) { if( isset($row['tax_amount_'.$tax]) ) $row['tax_amount_'.$tax] = wc_round_tax_total( $this->find_tax_by_label($product_taxes,$tax)); if( isset($row['tax_percentage_'.$tax]) ) $row['tax_percentage_'.$tax] = $this->find_tax_by_label($product_tax_rates,$tax); } return $row; } function find_tax_by_label($taxes,$label) { $value = 0; foreach($taxes as $key=>$v) { if( strpos($key,$label) !== false) { $value = $v; break; } } return $value; } } new WOE_add_product_shipping_taxes();
- This reply was modified 3 years, 3 months ago by algol.plus.
- This reply was modified 3 years, 3 months ago by algol.plus.
I will try what you post.
I would like the following:
Price of item | 25% TAX | Subtotal for 25% before tax | 15% Tax | Subtotal for 15% before tax
which according to my screenshot translates to:
78.26 | 0 | 0 | 11.74 | 66.52
199,20 | 49,8 | 149,4 | 0 | 0hello
my code already add this field, use “Total XXX Amount”
- The topic ‘Split Order Subtotal Amount into different tax brackets’ is closed to new replies.