Reverse Charge VAT for EU Business Buyers
Removes VAT for business customers in another EU country who enter a VAT number, and adds a "reverse charge" note to the order, as cross-border B2B sales require.
Opens WPIDE on
Code
$wpide_eu_countries = array( 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' );
$wpide_reverse_charge = function ( $country, $vat ) use ( $wpide_eu_countries ) {
$base = WC()->countries->get_base_country();
return '' !== trim( (string) $vat ) && $country !== $base && in_array( $country, $wpide_eu_countries, true );
};
add_action( 'woocommerce_checkout_update_order_review', function ( $post_data ) use ( $wpide_reverse_charge ) {
parse_str( (string) $post_data, $posted );
WC()->customer->set_is_vat_exempt( $wpide_reverse_charge( (string) ( $posted['billing_country'] ?? '' ), $posted['billing_vat_number'] ?? '' ) );
} );
add_action( 'woocommerce_checkout_process', function () use ( $wpide_reverse_charge ) {
// phpcs:ignore WordPress.Security.NonceVerification -- WooCommerce verifies the checkout nonce.
$exempt = $wpide_reverse_charge( wc_clean( wp_unslash( $_POST['billing_country'] ?? '' ) ), wc_clean( wp_unslash( $_POST['billing_vat_number'] ?? '' ) ) );
WC()->customer->set_is_vat_exempt( $exempt );
} );
add_action( 'woocommerce_checkout_create_order', function ( $order ) {
if ( WC()->customer && WC()->customer->get_is_vat_exempt() && $order->get_meta( '_billing_vat_number' ) ) {
$order->update_meta_data( '_wpide_reverse_charge', 'yes' );
}
}, 20 );
add_action( 'woocommerce_email_after_order_table', function ( $order ) {
if ( 'yes' === $order->get_meta( '_wpide_reverse_charge' ) ) {
echo '<p>' . esc_html( 'VAT reverse charge: the customer accounts for VAT (Article 196, Council Directive 2006/112/EC).' ) . '</p>';
}
} );
add_action( 'woocommerce_admin_order_data_after_billing_address', function ( $order ) {
if ( 'yes' === $order->get_meta( '_wpide_reverse_charge' ) ) {
echo '<p><strong>' . esc_html( 'VAT reverse charge applied' ) . '</strong></p>';
}
} );
Notes
Needs the "EU VAT Number Field With Format Check" snippet for the billing_vat_number field; confirm the rules for your business with your accountant.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.