首页 > 解决方案 > 当公司来自欧盟时,在 WooCommerce 中添加“增值税反向收费”

问题描述

我有一个使用 WooCommerce 订阅的带有 Wordpress 和 WooCommerce 的 B2B 网上商店。

当我销售数字商品时,我需要为欧盟公司的订单添加特殊的增值税规则。

我的商店位于荷兰。

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

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

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

会计师要求欧盟的订单有一条税线,上面写着:VAT REVERSE CHARGE。

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

标签: phpwordpresswoocommercewoocommerce-subscriptionstax

解决方案


您可以使用这个简单的代码片段来完成这项工作,在订单总额部分的税行中显示除荷兰以外的欧洲国家/地区的文本“增值税反向收费” :

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 文件中。测试和工作。


推荐阅读