# EU VAT Guard for WooCommerce

[![WordPress Plugin Version](https://img.shields.io/badge/WordPress-5.0%2B-blue.svg)](https://wordpress.org/)
[![WooCommerce Version](https://img.shields.io/badge/WooCommerce-4.0%2B-purple.svg)](https://woocommerce.com/)
[![PHP Version](https://img.shields.io/badge/PHP-8.2%2B-green.svg)](https://php.net/)
[![License](https://img.shields.io/badge/License-GPLv2%2B-red.svg)](https://www.gnu.org/licenses/gpl-2.0.html)

[Official Plugin Download](https://wordpress.org/plugins/eu-vat-guard-for-woocommerce/)

**EU VAT Guard for WooCommerce** is a powerful plugin that adds advanced EU VAT number management and validation to your WooCommerce store. It helps you collect, validate, and manage company VAT numbers for your B2B customers, ensuring compliance and a smooth checkout experience.

## Features

- **Company Name & VAT Number Fields**
  - Adds company name and VAT number fields to registration, account, and checkout forms.
  - Fields can be set as required or optional via the admin settings.

- **EU VAT Number Validation**
  - Offline (format/structure) validation for all EU VAT numbers.
  - Optional real-time validation with the official [VIES](https://ec.europa.eu/taxation_customs/vies/) webservice.
  - Option to allow checkout if VIES is unavailable (configurable in settings).

- **Advanced Customization** *(New in v1.1.0)*
  - Custom field labels and exemption messages
  - Option to disable VAT exemption while keeping validation
  - WPML compatibility for multilingual stores
  - Advanced settings tab for fine-tuning

- **PDF Invoice Integration** *(New in v1.1.0)*
  - Full compatibility with WooCommerce PDF Invoices & Packing Slips
  - VAT numbers and exemption status on PDF invoices
  - Template helper functions for custom implementations

- **VAT Rate Importer** *(New in v1.2.0)*
  - Import an EU VAT rate snapshot verified on 12 October 2026 for all 27 member states
  - Support for standard rates and one primary reduced rate per country
  - WooCommerce-style country selection interface
  - Uses WooCommerce's default reduced tax class with translation-safe detection
  - See [VAT rates and upgrade instructions](VAT-RATES-INFO.md) for official sources, import presets and product/region limits

- **WooCommerce Integration**
  - Classic checkout restores VAT from the current WooCommerce session for guests and logged-in users, with saved account VAT data as a fallback.
  - VAT number is saved to the order and displayed in the WooCommerce admin order screen and order emails.

- **Admin Settings Page**
  - Located under WooCommerce > VAT Guard.
  - Configure which fields are required.
  - Enable/disable VIES validation and error handling.
  - Friendly thank you message and easy-to-use options.

## Getting Started

1. **Install the Plugin**
   - Upload the plugin folder to your `/wp-content/plugins/` directory, or install via the WordPress admin.
   - Activate the plugin through the 'Plugins' menu in WordPress.

2. **Configure Settings**
   - Go to **WooCommerce > VAT Guard** in your WordPress admin.
   - Choose which fields are required (Company Name, VAT Number).
   - Enable VIES validation if you want real-time VAT number checks.
   - Optionally, allow checkout if VIES is unavailable.

3. **Usage**
   - Customers will see the new fields on registration, account, and checkout forms.
   - VAT numbers are validated according to your settings.
   - VAT numbers are shown in the order admin and in order emails.

## Development

### Requirements
- WordPress 5.0+
- WooCommerce 4.0+
- WooCommerce 8.9+ for the Block Checkout VAT field
- PHP 8.2+
- PHP SOAP extension (`ext-soap`), required only when VIES validation is enabled

Release checks run on WordPress 7.2 RC3, WooCommerce 11.3.1 and PHP 8.4.27. Older minimum versions are not covered by this release's test run.

### Classic checkout field customization

In **EU VAT Guard → Settings**, enable **Hide VAT number until a company name is entered** to show the VAT field only for customers with a billing company name. Disable **Require Company Name** if private customers should also be able to check out. **Require VAT Number** then applies only when a company name is present. Clearing the company removes VAT exemption and excludes the VAT value from the order; the browser keeps the typed VAT value so it can be restored when the company is entered again.

In **Advanced**, set **Company Name Placeholder** and **VAT Number Placeholder** independently of their labels. Empty settings retain the existing label-based placeholders. Enable **Remove placeholder text from the company and VAT fields** to remove both placeholders. Custom placeholders support WPML translation. These options apply to classic checkout.

### Updating to 1.5.0

The plugin update refreshes the importer's bundled rate snapshot; it does not automatically change your store's tax rows. Export your tax settings, review obsolete country/class rows, then import the updated rates and check product tax classes. A changed percentage creates a new row if no matching percentage exists, so remove obsolete rows deliberately. The first listed reduced rate is an import preset, not a universal rate for every product. See [VAT-RATES-INFO.md](VAT-RATES-INFO.md).

### File Structure
```
eu-vat-guard-for-woocommerce/
├── includes/
│   ├── class-vat-guard.php              # Main plugin class
│   ├── class-vat-guard-admin.php        # Admin interface
│   ├── class-vat-guard-vies.php         # VIES validation
│   └── class-vat-guard-block-integration.php # Block checkout support
├── assets/
│   └── js/
│       └── vat-guard-block-checkout.js  # Block checkout JavaScript
├── languages/
│   ├── compile-translations.php         # Translation compiler
│   └── *.po, *.mo                      # Translation files
├── readme.txt                          # WordPress.org readme
├── README.md                           # This file
└── vat-guard-woocommerce.php           # Main plugin file
```

### Translation

The plugin supports all 27 EU languages. To compile translations:

```bash
cd languages/
php compile-translations.php
```

### WordPress.org Submission

This plugin uses:
- **Text Domain**: `eu-vat-guard-for-woocommerce`
- **Plugin Slug**: `eu-vat-guard-for-woocommerce`
- **Stable Tag**: `1.5.4`

## Changelog

### Version 1.5.4 — 26 November 2026

- **Fixed**: VAT exemption notice is visible again in the block-based checkout order summary (WooCommerce 11.3+)
- **Improved**: Exemption notice is rendered through the WooCommerce order summary slot instead of DOM injection, and shown as a subtle text line
- **Removed**: Debug logging from block checkout VAT validation
- **Tested**: Compatibility with WordPress 7.2 and WooCommerce 11.3

### Version 1.5.3 — 18 November 2026

- **Fixed**: VAT number and exemption status now appear on PDF invoices attached to order emails (WooCommerce PDF Invoices & Packing Slips), not only on invoices generated from the order screen

### Version 1.5.2 — 4 November 2026

- **Fixed**: Guest VAT numbers are restored from the WooCommerce session when returning to classic checkout
- **Fixed**: Current session VAT edits, including a deliberately cleared field, take precedence over saved account VAT data
- **Improved**: VAT prefill preserves values supplied by earlier checkout filters

### Version 1.5.1 — 14 October 2026

- **Added**: Optional company-based VAT field visibility in classic checkout, with matching required-field validation and exemption removal when company is empty
- **Added**: Custom company/VAT placeholders with WPML support and an option to remove both placeholders in classic checkout
- **Fixed**: Missing PHP SOAP support no longer causes a fatal error; VIES failures are logged without printing into checkout or API responses
- **Fixed**: VAT format validation accepts short Romanian numbers and rejects eleven-digit Belgian numbers while retaining nine-digit Belgian input support
- **Fixed**: Order VAT and exemption metadata use WooCommerce's order API; PDF helpers no longer restore stale exemption status from legacy postmeta

### Version 1.5.0 — 12 October 2026
- **Updated**: EU VAT rate snapshot verified against official sources, with corrected Czech, Estonian, Finnish, Lithuanian, Romanian and Slovak rates and additional national special tiers
- **Fixed**: Classic and Block Checkout determine exemption before calculating totals, including address, shipping and final submission changes
- **Fixed**: Unrelated additional checkout fields preserve customer exemption, order metadata and other plugins' errors
- **Fixed**: Successful VAT validation clears stale country notices while preserving payment and coupon errors
- **Fixed**: Clearing optional VAT synchronizes session/customer data and immediately restores tax
- **Fixed**: Admin order VAT edits validate exemption eligibility rather than always granting exemption
- **Fixed**: Graceful handling when WooCommerce is missing or inactive
- **Improved**: Rate import documentation explains presets, territorial/product limitations and obsolete rate rows

### Version 1.4.7
- **Fixed**: Prevented the VAT number field from appearing twice on the Account Details page when block checkout support is enabled
- **Fixed**: Kept WooCommerce's block checkout VAT field synchronized with the plugin's canonical customer VAT data, including when clearing the field

### Version 1.4.6
- **Changed**: Decreased minimum PHP version to 8.2

### Version 1.4.5
- **Fixed**: Greek VAT numbers now compare the EU VAT prefix `EL` against WooCommerce's Greece country code `GR` during billing, shipping, and exemption checks

### Version 1.4.4
- **Tested**: Compatibility with Wordpress 6.9.4

### Version 1.4.3
- 🐛 **Fixed**: VAT Rate Importer now resolves the default reduced tax class in a translation-safe way (localized class names)
- 🔧 **Changed**: Importer now imports only the primary reduced VAT rate per country into WooCommerce's default reduced class
- 📝 **Improved**: Importer descriptions and docs updated to match current reduced-rate behavior

### Version 1.4.2
- 🐛 **Fixed**: Prevented stale VAT numbers from being reinstated in block checkout when customers update VAT after guest orders or during checkout

### Version 1.4.1
- 🐛 **Fixed**: Skip registration VAT/company validation for block checkout account creation (Store API) when Create account during checkout is enabled

### Version 1.4.0
- ✨ **Added**: New option to hide company and VAT fields from registration form while keeping them on checkout and account pages
- ✨ **Added**: Plugin compatibility option to override B2B plugins that interfere with VAT exemption (WooCommerce B2B, etc.)
- 🔧 **Improved**: Smart context detection for B2B plugin override - only applies during checkout, cart, payment processing, and for logged-in users with VAT numbers
- ⚡ **Improved**: More efficient hook registration - registration form hooks are only added when needed
- 🤝 **Enhanced**: Better compatibility with third-party B2B plugins that modify VAT behavior
- 🏗️ **Technical**: Added conditional hook registration to improve performance when features are disabled

### Version 1.3.13
- **Fixed**: Fixed pricing visible with VAT in shop with B2B plugin

### Version 1.3.12
- **Improved**: Added an agressive init hook to override interfering plugins

### Version 1.3.11
- **Improved**: Added filter on woocommerce_order_is_vat_exempt to handle interfering plugins


### Version 1.3.10
- 🐛 **Fixed**: Checkbox settings now properly save unchecked state on all server configurations
- 🔧 **Technical**: Added hidden input fields to ensure unchecked checkboxes submit '0' value
- ✨ **Improved**: Enhanced form reliability across different PHP/WordPress environments

### Version 1.3.9
- 🔧 **Improved**: Refactored settings sanitization for better code maintainability
- 🏗️ **Technical**: Simplified checkbox sanitization using inline callbacks in register_setting()
- 📝 **Technical**: Improved code organization by removing redundant filter hooks and methods

### Version 1.3.8
- 🐛 **Fixed**: Block checkout setting now properly saves as string type for better compatibility
- 🔧 **Technical**: Improved settings registration for block checkout option

### Version 1.3.7
- 🎨 **Enhanced**: Completely redesigned Help & Support tab with comprehensive documentation
- ✨ **Improved**: Better organized admin interface with clearer navigation
- 📚 **Added**: Common questions section in Help tab for quick answers
- 🔗 **Added**: Useful links section with direct access to documentation and resources
- 💬 **Enhanced**: More intuitive support and review prompts throughout admin interface

### Version 1.3.6
- 🎨 **Improved**: Updated admin interface with direct links to WordPress.org support and reviews
- ✨ **Enhanced**: Better user experience for getting help and leaving feedback

### Version 1.3.5
- ✅ **Compatibility**: Tested and confirmed compatible with WordPress 6.9
- 🔧 **Technical**: Updated version number for WordPress 6.9 release compatibility

### Version 1.3.4
- 🔧 **Technical**: Removed duplicate PDF integration initialization from main class
- 🔧 **Technical**: Improved code structure with PDF integration exclusively initialized through admin class
- 🔧 **Technical**: Reduced redundant code execution during plugin initialization

### Version 1.3.3
- ✨ **Added**: VAT information display on order confirmation and My Account pages
- 🎨 **Enhanced**: Smart display logic for block vs classic checkout
- 🔧 **Changed**: All meta keys now use `_eu_vat_guard_` prefix
- 🐛 **Fixed**: Admin error notices, block integration, and VAT rate importer issues

### Version 1.3.0
- 🏗️ **Major**: Implemented proper PHP namespacing (`Stormlabs\EUVATGuard`)
- 📦 **New**: Added comprehensive plugin constants for better code organization
- 🔧 **Improved**: Enhanced code structure following WordPress best practices
- 🌍 **Updated**: Completed translations for Dutch, French, and German
- 🎨 **Enhanced**: Admin order edit VAT field now shows read-only when not editing
- 📚 **Added**: Comprehensive documentation (NAMESPACE-CHANGES.md, NAMING-CONVENTIONS.md)
- ✅ **Maintained**: 100% backward compatibility with existing installations
- 🔒 **Security**: Enhanced code security through proper namespacing

### Version 1.2.0
- ✨ **New**: VAT Rate Importer tool for all 27 EU member states
- ✨ **New**: Support for special VAT categories (food, books, pharmaceuticals, hotels)
- 🔧 **Improved**: Enhanced WooCommerce integration with smart country filtering
- 📊 **Added**: Complete VAT rates overview table

### Version 1.1.0
- ✨ **New**: Advanced settings tab with exemption rules customization
- ✨ **New**: Custom field labels and exemption messages
- ✨ **New**: WPML compatibility for custom strings
- ✨ **New**: PDF invoice integration for WooCommerce PDF Invoices & Packing Slips
- ✨ **New**: PDF template helper functions
- 🔧 **Improved**: Admin interface with separate option groups
- 🐛 **Fixed**: Admin options not saving correctly between tabs
- 🔒 **Enhanced**: Security with proper nonce verification suppression
- 📝 **Updated**: Text domain for better WordPress.org compatibility

### Version 1.0.0
- 🎉 Initial release
- Company name and VAT number fields
- EU VAT number format validation
- Optional VIES real-time validation
- Automatic VAT exemption for B2B transactions
- WooCommerce block checkout support
- Admin settings interface

## Support

- **WordPress.org**: [Plugin Support Forum](https://wordpress.org/support/plugin/eu-vat-guard-for-woocommerce/)
- **Reviews**: [Leave a Review](https://wordpress.org/plugins/eu-vat-guard-for-woocommerce/#reviews)
- **Website**: [https://stormlabs.be/](https://stormlabs.be/)

## License

This plugin is licensed under the GPLv2 or later.

---
**Thank you for using EU VAT Guard for WooCommerce!**
