问题描述
我有一个使用 WooCommerce 订阅的 wordpress 和 WooCommerce 的 B2B 网上商店。
当我销售数字商品时,我需要为欧盟内部公司的订单添加特殊的增值税规则。
我的商店位于荷兰。
我正在使用此插件来验证增值税号:https://woocommerce.com/products/eu-vat-number/
我自己国家的公司和欧盟以外的公司一切顺利。
但是当公司在欧盟内部时,插件会从订单中删除所有增值税行。我已联系 WooCommerce,但他们不提供定制支持。
会计师要求欧盟的订单有一条税线,上面写着: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 文件中。经测试有效。