当公司来自欧盟时,在WooCommerce中添加"VAT REVERSE CHARGE"



我有一个B2B网站与Wordpress和WooCommerce使用WooCommerce订阅。

由于我正在销售数字商品,我需要在欧盟内的公司订单中添加特殊的增值税规则。

我的店设在荷兰。

我使用这个插件来验证增值税号码:https://woocommerce.com/products/eu-vat-number/

对于我自己国家的公司和欧盟以外的公司来说,一切都很顺利。

但是当公司在欧盟内部时,插件会从订单中删除所有增值税。我已经联系了WooCommerce,但他们不提供自定义支持。

要求会计在欧盟的订单有一个税号:VAT REVERSE CHARGE。

我的问题:我想编写一个自定义操作,仅在结账时为欧盟国家的订单添加增值税行。有人能帮我开始吗?

您可以使用这个简单的代码片段来完成这项工作,在订单总额部分的税收行中显示文本"Vat reverse charge">欧洲国家(荷兰除外):

add_filter( 'woocommerce_get_order_item_totals', 'insert_custom_line_order_item_totals', 10, 3 );
function insert_custom_line_order_item_totals( $total_rows, $order, $tax_display ){
$eu_countries = WC()->countries->get_european_union_countries( 'eu_vat' ); // Get EU VAT Countries
unset($eu_countries['NL']); // Remove Netherlands
if ( in_array( $order->get_billing_country(), $eu_countries ) ) {
$order_total = $total_rows['order_total']; // Store order total row in a variable
unset($total_rows['order_total']); // Remove order total row
// Tax row
$total_rows['tax'] = array(
'label' => WC()->countries->tax_or_vat() . ':',
'value' => strtoupper( sprintf(  __('%s reverse charge', 'woocommerce'), WC()->countries->tax_or_vat() ) ),
);
$total_rows['order_total'] = $order_total; // Reinsert order total row
}
return $total_rows;
}

代码放在活动子主题(或活动主题)的functions.php文件中。

最新更新