Tax Names
-
We currently have three different tax rates. GST, HST, and QST. I only see an option to get the tax total. I need to be able to have a column for each Tax Name and it have the amount charged. So potentially, an order could be charged three different taxes, and I need to be able to separate those into columns.
-
yes, I’ve got your email and sample file.
code to get order taxes ( above line “Order Total:”)
class WOE_multi_taxes_order{ var $gst_tax = 0; var $hst_tax = 0; var $qst_tax = 0; function __construct() { add_filter('woe_get_order_fields', array($this,'add_order_fields'), 10, 1); add_filter('woe_order_export_started',array($this,'fetch_order_taxes'), 10, 1); //for XLS , woe_get_order_{$format}_value_{$field} add_filter('woe_get_order_xls_value_gst_tax',array($this,'get_gst_tax'), 10, 2); add_filter('woe_get_order_xls_value_hst_tax',array($this,'get_hst_tax'), 10, 2); add_filter('woe_get_order_xls_value_qst_tax',array($this,'get_qst_tax'), 10, 2); } function add_order_fields($fields) { $fields['gst_tax'] = array('label'=>'TAXES GST','checked' => 1, 'segment'=>'','colname'=>'TAXES GST'); $fields['hst_tax'] = array('label'=>'TAXES HST','checked' => 1, 'segment'=>'','colname'=>'TAXES HST'); $fields['qst_tax'] = array('label'=>'TAXES QST','checked' => 1, 'segment'=>'','colname'=>'TAXES QST'); return $fields; } function fetch_order_taxes($order_id) { //reset values $this->gst_tax = $this->hst_tax = $this->qst_tax = 0; //read taxes $order = new WC_Order($order_id); foreach ( $order->get_items('tax') as $item_id=>$item ) { // must add shipping taxes if($item['label'] == 'GST')$this->gst_tax = $item['tax_amount'] + $item['shipping_tax_amount']; if($item['label'] == 'HST')$this->hst_tax = $item['tax_amount'] + $item['shipping_tax_amount']; if($item['label'] == 'QST')$this->qst_tax = $item['tax_amount'] + $item['shipping_tax_amount']; } } function get_gst_tax($value, $order) { return $this->gst_tax; } function get_hst_tax($value, $order) { return $this->hst_tax; } function get_qst_tax($value, $order) { return $this->qst_tax; } } new WOE_multi_taxes_order();I just added the above code to my functions.php file. It adds the fields to the export, but they all have 0 in them instead of the tax values.
In the woocommerce_order_items table it looks like this: https://snag.gy/60VNov.jpg
In the woocommerce_order_itemmeta table, it has this: https://snag.gy/A5SuMJ.jpg
We are using the standard WooCommerce tax rates Admin > WooCommerce > Settings > Tax > Standard Rates.
This is the tax table: https://snag.gy/TVu3r4.jpg
-
This reply was modified 9 years, 8 months ago by
dwdonline.
some hooks were added in beta version, so provided code works in beta only.
you can contact me if you need it.
-
This reply was modified 9 years, 8 months ago by
algol.plus.
Code works since version 1.2.2
Hi,
Thanks for this solution. I have two additional questions:
Do i place this code in functions.php of my child theme?
I need to slightly adjust the code:
My tax names in Woocommerce are ‘BTW Hoog‘ and ‘BTW Laag‘. So they contain a whitespace.What code do i need to use for BTW Hoog? For example here:
var $gst_tax = 0;
var $hst_tax = 0;because simply replacing ‘gst’ by ‘BTW Hoog’ does not work:
var $BTW Hoog_tax = 0;
var $BTW Laag = 0;I have two tax rates and i want to export each in a separate column.
Thank you in advance.hi
Yes, you must put it in in functions.php of child theme
You must replace space with “_” , look at the updated code
class WOE_multi_taxes_order{ var $BTW_Hoog = 0; var $BTW_Laag = 0; function __construct() { add_filter('woe_get_order_fields', array($this,'add_order_fields'), 10, 1); add_filter('woe_order_export_started',array($this,'fetch_order_taxes'), 10, 1); //for XLS , woe_get_order_{$format}_value_{$field} add_filter('woe_get_order_xls_value_BTW_Hoog',array($this,'get_BTW_Hoog'), 10, 2); add_filter('woe_get_order_xls_value_BTW_Laag',array($this,'get_BTW_Laag'), 10, 2); } function add_order_fields($fields) { $fields['BTW_Hoog'] = array('label'=>'BTW Hoog','checked' => 1, 'segment'=>'','colname'=>'BTW Hoog'); $fields['BTW_Laag'] = array('label'=>'BTW Laag','checked' => 1, 'segment'=>'','colname'=>'BTW Laag'); return $fields; } function fetch_order_taxes($order_id) { //reset values $this->BTW_Hoog = $this->BTW_Laag = 0; //read taxes $order = new WC_Order($order_id); foreach ( $order->get_items('tax') as $item_id=>$item ) { // must add shipping taxes if($item['label'] == 'BTW Hoog')$this->BTW_Hoog = $item['tax_amount'] + $item['shipping_tax_amount']; if($item['label'] == 'BTW Laag')$this->BTW_Laag = $item['tax_amount'] + $item['shipping_tax_amount']; } } function get_BTW_Hoog($value, $order) { return $this->BTW_Hoog; } function get_BTW_Laag($value, $order) { return $this->BTW_Laag; } } new WOE_multi_taxes_order(); -
This reply was modified 9 years, 8 months ago by
The topic ‘Tax Names’ is closed to new replies.