WooCommerce Xero add-on tax label bug
-
Hello! Firstly, apologies, ordinarily I would send this via the appropriate channels on the WooCommerce support system, but unfortunately I do not own the license for the WooCommerce Xero add-on, the original site developer does & therefore the WooCommerce site won’t let me.
Problem: Xero integration plugin does not return the shipping tax label set in WooCommerce tax rates options ( WC_XR_Line_Item_Manager -> build_shipping() does not set a label at all?) so get_tax_type() returns the default label (VAT in this case) which then matches with the wrong tax type in Xero, returning the wrong account code for shipping taxes. E.g. from log:
04-22-2020 @ 14:38:24 – Getting tax type for line item (Shipping Charge)
04-22-2020 @ 14:38:24 – – Rate (20) has an empty Tax Name. Will use label (VAT) by default.
04-22-2020 @ 14:38:24 – – Searching rates for label (VAT (20.00%)) and rate (20)
04-22-2020 @ 14:38:24 – – Matching rate (Name) (20% (VAT on Expenses)) and rate (20)
04-22-2020 @ 14:38:24 – – No match
[log truncated for brevity – can provide on request]
04-22-2020 @ 14:38:24 – – Matching rate (Name) (VAT (20.00%)) and rate (20)
04-22-2020 @ 14:38:24 – – Name matches
04-22-2020 @ 14:38:24 – – Rate matches
04-22-2020 @ 14:38:24 – – Found and returning tax type (TAX002)Returning error: ERROR creating Xero invoice: ErrorNumber: 10 ErrorType: ValidationException Message: A validation exception occurred Detail: The TaxType code ‘TAX002’ cannot be used with account code ‘425’.
Problem since: 2020-04-21 – version 1.7.29
Amusingly, this has only started happening since the shipping tax rate empty bug was fixed. Prior to that, because both the tax rate and tax label were empty it was silently failing and processing anyway, e.g.04-20-2020 @ 11:24:09 – Getting tax type for line item (Shipping Charge)
04-20-2020 @ 11:24:09 – – Rate (0) has an empty Tax Name. Will use label (VAT) by default.
04-20-2020 @ 11:24:09 – – Searching rates for label (VAT (0.00%)) and rate (0)
[log truncated for brevity – can provide on request]
04-20-2020 @ 11:24:09 – – Could not find a cached tax type for that label and rate. Attempting to add new one to Xero.
04-20-2020 @ 11:24:09 – – Setting ReportTaxType to (INPUT)
04-20-2020 @ 11:24:09 – – Error – unable to add rate to Xero – Returning empty tax type ()I’ve been able to bodge a fix in place for this client by adding a filter to woocommerce_xero_line_item_tax_rate and forcing a label if is_shipping_line_item is true:
/**
* The Xero plugin doesn’t use shipping labels for this calculation, so we need to add one in
*
* @param array $tax_rate_array – the tax rate array being filtered, we just want to add a label in
* @return array
*/
function coolcovers_xero_shipping_rate_fix( $tax_rate_array ) {
if ( !empty( $tax_rate_array[‘is_shipping_line_item’] ) && empty( $tax_rate_array[‘label’] ) ) {
$tax_rate_array[‘label’] = ‘20% (VAT on Expenses)’;//todo: change this so it pulls the label out dynamically rather than being hardcoded?
}
return $tax_rate_array;
}
add_filter( ‘woocommerce_xero_line_item_tax_rate’, ‘coolcovers_xero_shipping_rate_fix’, 10, 1 );However, this isn’t ideal (and is currently hardcoded so a bit dodge) and would be better if the plugin pulled the tax label from the tax settings page properly.
Happy to provide further logs etc on request. Apologies again for sending this here – wasn’t sure where else it could go.
- The topic ‘WooCommerce Xero add-on tax label bug’ is closed to new replies.