=== EU VAT Check for WooCommerce ===
Contributors: catcodestudio
Tags: eu vat, vies, reverse charge, vat number, oss
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

EU VAT numbers at the WooCommerce checkout, checked live in VIES: reverse charge for valid B2B customers, with the proof stored on the order.

== Description ==

A shop in the EU that sells to businesses in other member states may leave VAT off the invoice — but only for a customer whose VAT number is valid, and the shop has to be able to show that it checked. This plugin does exactly that part, on the classic and the block checkout.

The customer enters a VAT number. The plugin checks it live against VIES, the European Commission's VAT Information Exchange System, and removes VAT from the order only when the number is valid, belongs to the customer's country and the sale is not a domestic one. The answer — including the VIES consultation number when you enter your own VAT number — is stored on the order, noted in the order history and kept in a check log.

**Moving from EU VAT Assistant?** It reached its end of life in 2022. This plugin reads what it left behind: the VAT numbers your customers saved are copied into the new field with one click (or automatically at their next login), and the order screen and the reports understand orders placed while EU VAT Assistant was in charge.

Free:

* VAT number field on the **classic checkout and the block checkout** (Additional Checkout Fields API), and in My Account → Addresses.
* Live check in **VIES** through the Commission's REST API, with the VIES **consultation number** when your own VAT number is set.
* **Reverse charge**: VAT is removed only for a valid number from another member state that matches the billing country. Domestic sales and goods delivered within the shop's own country keep VAT.
* Local format check against the VIES number structures first, so an obvious typo never costs a VIES round trip. Greece (EL) and Northern Ireland (XI) handled.
* A number VIES rejects either stops the order until it is corrected, or lets it through with VAT — your choice.
* While VIES or a member state is down: charge VAT (safe), or accept the number for now and have it re-checked every hour for three days, with the result noted on the order.
* The VAT number, the VIES answer, the name and address VIES returned and the consultation number stored on every order; a panel on the order screen (HPOS and legacy) with a "Check in VIES now" button; an "EU VAT" column in the orders list.
* A reverse-charge note on the thank-you page, in the e-mails and on the invoice of **PDF Invoices & Packing Slips** (which also picks up the VAT number).
* A check log of every VIES answer, filterable by answer, number, order and date.
* Test mode that uses the Commission's own test service (100 valid, 200 invalid, 300/301 unavailable …).
* "Test the connection" button: which member states are online right now, and a round trip to the test service.
* Translations: English and German (de_DE).

Pro (licence from catcode.com.ua):

* **Location evidence** stored with every order: billing country, delivery country, IP country (WooCommerce geolocation, no outside service) and VAT-number country, with contradictions flagged.
* **OSS report**: sales to consumers in other member states per country and VAT rate for a quarter, refunds included — and the **EC Sales List**: reverse-charge sales per customer VAT number. Both as CSV.
* **VAT rates from TEDB**: the standard rates of all 27 member states read from the European Commission's Taxes in Europe Database, compared with your tax table, and written into it after you look at the comparison. A weekly watch warns when a member state changes its rate.
* **Company-name matching**: the billing company is sent to VIES and the match result stored with the order.
* **Scheduled re-validation** of the VAT numbers your registered customers have saved.
* **CSV export** of the check log for an audit.

== Installation ==

1. Upload the plugin and activate it. WooCommerce must be active and taxes enabled (WooCommerce → Settings → General → Enable tax rates).
2. WooCommerce → EU VAT Check → Settings: enter **your own VAT number** (with the country prefix). VIES then returns a consultation number with every valid answer — the proof that you checked.
3. Press **Test the connection**.
4. Place a test order with the VAT number field filled in, on the checkout you use. Test mode lets you do this with the Commission's test numbers (100 = valid, 200 = invalid) before going live.

== Frequently Asked Questions ==

= Does this make my shop VAT compliant? =
It does the part that software can do: it checks the number where the law expects you to check it, removes VAT only when the conditions are met, and keeps the evidence. Whether a sale qualifies for reverse charge in your particular case, and what your invoices must say, is for you and your tax adviser. The OSS report and the EC Sales List are working figures for your return, not a filing.

= Which country is compared with the VAT number? =
The billing country. A French number with a German billing address keeps VAT (you can switch that rule off). A number from the shop's own country keeps domestic VAT, and so does an order whose goods are delivered within the shop's own country.

= What happens when VIES is down? =
You choose: charge VAT (the customer can reclaim it), or accept a correctly formatted number for now. Accepted orders are re-checked every hour for three days and the answer is noted on the order; if the number turns out invalid, the note tells you what to do.

= Does it work with the block checkout? =
Yes. The field is registered through WooCommerce's Additional Checkout Fields API, the decision is made while the Store API updates the customer, and the totals are recalculated right after — the cart and the order show the price without VAT as soon as the number is confirmed. A number that must stop the order stops it in the Store API, so closing the page or calling the API directly changes nothing.

= Where is the VAT number stored? =
On the customer as `billing_vat_number` (and in the block checkout's own field, kept in sync), on the order as `_billing_vat_number` — the key PDF invoice plugins read — and with the VIES answer in `_catcode_euvat_*` order meta.

= I used EU VAT Assistant. What happens to my data? =
Nothing is deleted or changed. On the settings tab, "Copy the numbers" copies each customer's saved number into this plugin's field where that field is still empty; the same happens for a customer at the next login. Old orders keep their data, the order screen shows what EU VAT Assistant recorded, and the reports count their reverse-charge orders. Deactivate EU VAT Assistant afterwards — two VAT plugins at once would show two fields.

= What happens when I delete the plugin? =
The check log survives, because it holds your VIES consultation numbers and tax records have to be kept for years. Define `CCEUVAT_DELETE_DATA` as true in wp-config.php before deleting if you really want it removed. The data stored on orders is never removed.

= Free and Pro =
The free version is complete for checking numbers and applying reverse charge. Pro features are unlocked with a licence key from catcode.com.ua. The 7-day trial starts only when you click it. A purchased licence keeps its Pro features after the term ends — only updates and support stop.

== External services ==

This plugin connects to the following services.

* **VIES — VAT Information Exchange System (European Commission).** Used to check a VAT number when a customer enters one at the checkout or in My Account, when an administrator presses "Check in VIES now" or "Test the connection", and for the scheduled re-checks. Sent: the country prefix and the VAT number; your own VAT number as requester when you set it; the billing company name only when Pro company-name matching is switched on. Endpoints: https://ec.europa.eu/taxation_customs/vies/rest-api/check-vat-number, …/check-vat-test-service and …/check-status. Service and disclaimer: https://ec.europa.eu/taxation_customs/vies/ — legal notice: https://commission.europa.eu/legal-notice_en — privacy: https://commission.europa.eu/privacy-policy-websites-managed-european-commission_en
* **TEDB — Taxes in Europe Database (European Commission)**, Pro only. Used when you open the VAT rates tab and, if you switch the watch on, once a week. Sent: the list of member states and today's date; nothing about your shop or customers. Endpoint: https://ec.europa.eu/taxation_customs/tedb/ws/ — privacy: https://commission.europa.eu/privacy-policy-websites-managed-european-commission_en
* **CatCode licence server** (catcode.com.ua). Used when you activate or deactivate a licence key, start the trial, and once a day to re-check an active key. Sent: the key, the site address, the module name, and for the trial the e-mail address you enter. Terms: https://catcode.com.ua/ — privacy: https://catcode.com.ua/privacy/

== Changelog ==

= 1.0.0 =
* First release.
