php - 当公司来自欧盟时,在 WooCommerce 中添加“增值税反向收费”
问题描述
我有一个使用 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 文件中。测试和工作。
推荐阅读
- html - Bootstrap 4:我希望我的列占据容器的整个宽度
- python - 什么是 Vaex 函数将字符串解析为 datetime64,相当于 pandas to_datetime,允许自定义格式?
- javascript - 有没有办法订阅 window.getSelection 中的更改?
- javascript - 根据键数组更改数据集对象的形状
- windows - xcopy 在 AppVeyor 中失败,在家工作:参数数量无效
- php - 是否可以将 *= 运算符与 round() 函数一起使用
- mysql - MySQL访问字符串就像一个数组
- git - 忽略 gitlab-ci 管道中的 Dockerfile
- rust - 特征作为结构对象初始化的通用参数
- flutter - 我想解决 Flutter App 构建失败的问题